-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHomework_function.cpp
More file actions
44 lines (41 loc) · 1.08 KB
/
Homework_function.cpp
File metadata and controls
44 lines (41 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include<iostream>
#include<iomanip>
#include<time.h>
using namespace std;
void checkNum( int num1 , int num2 ,bool &done);
void main()
{
int num1, num2 , num3 = 0;
bool done = true;
srand(time(NULL));
num2 = 1+(rand()%9);
cout <<"==============================================" << endl;
cout <<" ##### Welcome to guessing number game ##### " << endl;
cout <<"==============================================" << endl;
cout << "Secret number has been chosen"<<endl;
do{
cout << "Guess the number (1 to 10) : ";
cin >> num1;
num3++;
checkNum(num1,num2,done);
}while(done);
cout << "The secret number is " << num2 << endl;
cout << "You made " << num3 << " guesses" << endl;
cout <<"==============================================" << endl;
}
void checkNum (int num1 ,int num2 , bool &done)
{
if(num1 > num2)
{
cout << "The secret number is lower" << endl;
}
else if(num1 < num2)
{
cout << "The secret number is higher" << endl;
}
else if(num1 == num2)
{
cout << "Congratulations!" << endl;
done = false;
}
}