### 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.
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051`` ``````#include #include #include 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<

.....
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.