need help writing a program where the computer will think of a random number between 1 and 9 and the user has to guess what that number is. then if they guess the number right the program will say something like yay you won or something and reset. if you loose it will say something like you lost or something. i also need a score counter. i.e you guess right, you get 10pts. you guess wrong you loose 5 pts. and id like to be able to have tat counter go from round to round. 5 rounds. 1-9 will be on a grid 3x3 and i just need some help with the writing. im still having some little problems with writing simple if then statements so this is kinda huge for me. im using the WATCOM C++ compiler. this is what i have so far:
#include <iostream.h>
#include <random.h>
using namespace std;
int iAnswer;
int iGuess;
int iArray[10];
int main()
// This is a basic random find in a small matrix where the computer will randomly pick a number and you have to guess
//what that nuber is. If you guess correctly, or wongly, THE GAME will reset itself with a new number. haha you lost.
{
cout << iArray;
cout << "please enter a number between 1 and 9" << endl;
cin >> iGuess;
return 0;
}
and im sure some of it is wrong, but i just dont know where i need to go from here :/ any help would be great! thanks!
#include <iostream.h>
#include <cstdlib>
#include <time.h>
usingnamespace std;
int total_points;
int main()
// This is a basic random find in a small matrix where the computer will randomly pick a number and you have to guess
//what that nuber is. If you guess correctly, or wongly, THE GAME will reset itself with a new number. haha you lost.
{
srand((unsigned)time(0));
cout<<"Welcome to the Game\n";
while (1)
{
int random=(rand()%10);
int guess;
cout<<"Enter you guess:";
cin>>guess;
if (guess==random)
{
cout<<"Win\n";
total+=10;
}
else
{
cout<<"Fail'n"
total-=5;
}
cout<<"Your total is: "<<total<<"\nPlay again (y\n): ";
char ans;
cin>>ans;
if (ans=='y')
{
system ("cls");
continue;
}
elsebreak;
return 0;
}
We don't give out full solutions to problems on this forum, sargon. We have no guarantees that the OP will learn how the problem was solved or even glance at the solution for longer than the time it takes to copy and paste it as their own. Some do study the solution, but most don't.
haha, i was in a hurry...and @ Albatross: didn't know, besides... there's quite a few errors in there, like i said, i was in a hurry. he'll have his hands full fixing the code
and i used system because that's what begginers want and do, no need to complicate things for him