Dec 10, 2008 at 10:50am UTC
I don't understand your question.
BTW I like the idea of your program and I want to add it to my library.
There are a couple of things I don't understand in your code.
#include <conio.h>
#include <stdio.h>
#include <cstdlib>
#include <ctime>
srand((unsigned)time(0));
I'm a beginner in C++, and I haven't passed those headers if they were mentioned in the tutorial. Could you explain what those are used for? Thnx
Last edited on Dec 10, 2008 at 10:53am UTC
Dec 10, 2008 at 11:12am UTC
Define what you mean by having a menu at the end? I'd gather you want a menu that has - play again and exit?
Dec 10, 2008 at 12:40pm UTC
If you meant that you need a menu as
Mythios mentioned then I see the good I did.
I hope you don't mind that I edited your code but after the edit you have a menu after the game :D
This whole things will make your code look like this :
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
LABEL:
system("cls" );
srand((unsigned )time(0));
int R = rand() % 100 + 1;
int Y = 10;
int I;
int number;
cout << "Guess A Number" << endl;
while (Y > 0)
{
cin >> I;
if (I > R)
{
system("cls" );
cout << " You Have " << Y-1 << " Guesses Left!!!" << endl;
cout << "The Number Is Less Than " << I << "!!!" << endl;
Y -= 1;
}
else if (I == R)
{
system("cls" );
cout << "YYY YYY OOOOOOOOO UU UU WW WW IIII NN NN" << endl;
cout << " YYY YYY OOOOOOOOO UU UU WW WW NNN NN" << endl;
cout << " YYYYY OO OO UU UU WW WW IIII NN NN NN" << endl;
cout << " YYY OO OO UU UU WW WW WW IIII NN NN NN" << endl;
cout << " YYY OOOOOOOOO UUUUUUUUU WW WW WW WW IIII NN NN NN" << endl;
cout << " YYY OOOOOOOOO UUUUUUUUU WW WW IIII NN NN" << endl;
cout<<"Start a new game (Write 1)" <<endl;
cout<<"End Game (Write anything else)" <<endl;
cout<<"Enter your choice : " ;
cin>>number;
if (number==1)
goto LABEL;
_getch();
return 0;
}
else
{
system("cls" );
cout << " You Have " << Y-1 << " Guesses Left!!!" << endl;
cout << "The Number Is Greater Than " << I << "!!!" << endl;
Y -= 1;
}
}
system("cls" );
cout << "You Lose!!!" << endl;
cout << "The Number Was " << R << endl;
cout<<"Start a new game (Write 1)" <<endl;
cout<<"End Game (Write anything else" <<endl;
cout<<"Enter your choice : " ;
cin>>number;
if (number==1)
goto LABEL;
else if (number==2)
cout << "Press Any Key To End..." << endl;
_getch()
;
return 0;
}
Last edited on Dec 10, 2008 at 12:40pm UTC
Dec 10, 2008 at 9:27pm UTC
Yes i was looking for a menu at the end.
So If You Type one At The end you go back to the very start and if you press 2 you end right??
I Tried Copy And Paste and you only restart after you win and not after you lose.
Thanks,
MM
Last edited on Dec 10, 2008 at 9:58pm UTC
Dec 13, 2008 at 6:51am UTC
Well considering he wrote out the base of how to do it. Instead of copying and pasting - try to write the rest yourself and see how you go.