Someone please help

I am in a C++ class in college and i need some help with a project

It's a "guess the number game". i got it to work but the teacher said that it needs to be divided in to four separate functions or subroutines and I have no clue how to do that. Plus i need to add a way to count how many times it runs through the loop and print a massage that says
if it's less then 10 " you know the secret or got lucky"
if it is ten " you know the secret"
and more then "10 you could have done better"
i really need some help please and thank you

here is my code

#include <cstdlib>
#include <iostream>
#include <time.h>
using namespace std;


int main()
{
srand (time(0));
int number;
number= rand () % 1000+1;
printf("Welcome to guess the number\n i'm think of a number between 1 and 1000");
int guess;
do {
cout << "\nenter your guess:";
cin >> guess;
if (guess < number)
cout << "\nyour number is to low guess again";
else if ( guess > number)
cout << "\nyour number is to high guess again";
else
cout <<"\nyour guess is correct! Congraulations!";
}while (guess != number);
system ("PAUSE");


return 0;


}
Hi, I fixed your code as you request.
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
45
46
47
48
49
50
51
#include <cstdlib>
#include <iostream>
#include <time.h>

using namespace std;

int getGuessNumber(int *number){
	srand (time(0));
	*number= rand () % 1000+1;
}

void guess(int *number, int *guessCounts){
	int guess = 0;
	do {
		cout << "\nenter your guess:";
		cin >> guess;
		(*guessCounts)++;
		if (guess < *number)
			cout << "\nyour number is to low guess again";
		else if ( guess > *number)
			cout << "\nyour number is to high guess again";
		else
			cout <<"\nyour guess is correct! Congraulations!\n";
	}while(guess != *number);
}

void printTheInfo(int *guessCounts){
	if(*guessCounts	< 10){
		cout << "you know the secret or got lucky" << endl;
	}else if(*guessCounts == 10){
		cout << "you know the secret" << endl;
	}else{
		cout << "10 you could have done better" << endl;
	}
}

int main()
{
	int number;
	int guessCounts = 0;
	
	getGuessNumber(&number);	//Generate the guess number
	
	printf("Welcome to guess the number\n i'm think of a number between 1 and 1000\n");
	//cout<<number<<endl;
	
	guess(&number, &guessCounts);
	printTheInfo(&guessCounts);
	system ("PAUSE");
	return 0;
}


.....
Last edited on
@hulibarri, I would like to see you try to use a switch statement to solve this.
Topic archived. No new replies allowed.