guess game
In this game, you play with computer for N rounds (N should be provided by the user and passed into the function as a parameter). In each round, the computer generates a random number between 1 and 3 (including 1 and 3), and the computer asks you to guess the number. If your given number is just the same as the generated number, you win; otherwise you lose. Generate a final report showing how many times you win and how many times you lose.
Function prototype: void guess_game(int N ) ;
Hi i need help with the N rounds part cant seems to call the function for N times.
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
using namespace std;
void print_multitable();
void guess_game();
int main()
{ int x;
cout << "Press 1 for multiplication table or 2 for guessing game: " << endl;
cin >> x;
if (x == 1)
print_multitable();
if (x == 2)
guess_game();
else
cout << "You have exited the menu" << endl;
return 0;
}
void print_multitable(void)
{
int i,j;
for (i=0; i<=9; i++){
for (j=1; j<=i; j++){
cout << i << "x" << j << "=" << i*j << " ";
}
cout << endl << setw(i-9);
}
return;
}
void guess_game(int N)
{
srand((unsigned)time(0));
int g;
int y = rand()% 3+1 ;
cout << "Enter the number of rounds to play: " << endl;
cin >> N;
cout << "Guess a number from 1 to 3: "<< endl;
cin >> g;
if (g==y)
cout<< "You win" << endl;
if (g!=y)
cout << "you lose, the number was " << y << endl;
return ;
}