I have written code for a game --- when the users say they want to play again, i want the screen to clear -- any help wold be appreciated..thanx in adv
Printable View
I have written code for a game --- when the users say they want to play again, i want the screen to clear -- any help wold be appreciated..thanx in adv
How have you coded it....is it for a char based console (In which case go to lightatdawn's board faqs.....is it for DirectX, OpenGL, GDI or what???
It is for char here is the code:
//This program will play the Rock Paper Scissors Game
#include <iostream.h>
#include <ctype.h>
int main()
{
char user_one, user_two, response = 'Y';
do
{
cout << "Welcome To Rock, Paper, Scissors.\n";
cout << "A Fun Game For All Ages !!!!\n\n\n";
cout << " The game is simple, just enter P for Paper, R for Rock, and S for Scissors\n\n\n";
cout << "Player 1, Please enter R, P, or S: ";
cin >> user_one;
user_one = toupper(user_one);
cout << "Player 2, Please enter R, P, or S: ";
cin >> user_two;
user_two = toupper(user_two);
if (user_one == 'P' && user_two == 'P')
{
cout << "Nobody Wins, Sorry\n\n\n\n";
}
else if (user_one == 'P' && user_two == 'R')
{
cout << "The Winner is: Player 1, Paper wraps Rock\n\n\n\n";
}
else if (user_one == 'P' && user_two == 'S')
{
cout << "The Winner is: Player 2, Scissors cut Paper\n\n\n\n";
}
else if (user_one == 'R' && user_two == 'R')
{
cout << "Nobody Wins, Sorry\n\n\n\n";
}
else if (user_one == 'R' && user_two == 'P')
{
cout << "The Winner is: Player 2, Paper wraps Rock\n\n\n\n";
}
else if (user_one == 'R' && user_two == 'S')
{
cout << "The Winner is: Player 1, Rock breaks Scissors\n\n\n\n";
}
else if (user_one == 'S' && user_two == 'S')
{
cout << "Nobody Wins, Sorry\n\n\n\n";
}
else if (user_one == 'S' && user_two == 'R')
{
cout << "The Winner is: Player 2, Rock breaks Scissors\n\n\n\n";
}
else if (user_one == 'S' && user_two == 'P')
{
cout << "The Winner is: Player 1, Scissors cut Paper\n\n\n\n";
}
cout << "Would you like to play another game (y/n): ";
cin >> response;
response = toupper(response);
cin.clear();
}while (response == 'Y');
return 0;
}
Try here
Thank you....:D :D :D
clrscr();
If you put this line anywhere you want the screen to clear in your code making sure to remember the #include <conio.h> library file, the screen will clear.
It is used in my compiler which is Borland Turbo C++ V3.1
Hope this helps.
Rob.
One other question and my program qill be complete.....Suppose I wanted to have it test to see if the user put in something other than the R P or S ---- I've tried a few things but it keeps giving me errors..any ideas on that one..??? Thanks again to the replyersof this request
mmmmmmmmm, well I personally would have used a case, switch, break style of code for this program.
Im not knocking it though, your code is good, Im sure there is a way you can do this using your existing work, but take a look at switch, case, and break in the help files of your compiler, it may lead you to the answer.
Good Luck,
Rob.
Or a much easier way;
Code:cin.get(user_one);
if(user_one != 'P' &&
user_one != 'R' &&
user_one != 'S'){
cout << "Illegal move\n";
return 0;
}
Thanks Fordy...:cool: :D
This funtion is not supported in Microsoft visual C++.Quote:
Originally posted by Robert_Ingleby
clrscr();
If you put this line anywhere you want the screen to clear in your code making sure to remember the #include <conio.h> library file, the screen will clear.
It is used in my compiler which is Borland Turbo C++ V3.1
Hope this helps.
Rob.
Ive added the conio.h lib and the clrscr(); still doesnt seem to want to work....ive put in several places in the code (???)
Also::::a huge thanks goes out to Fordy... :) :) your code worked...
Since MS C++ doesnt support that lib file...are there any other suggestions to clearing the screen..???
>>Since MS C++ doesnt support that lib file...are there any other suggestions to clearing the screen..???
Its in the faqs that I linked you to earlierQuote:
WINDOWS OPTION: (Credit: Sunlight)
Just call the function clrscr(). Simple as that.
#include <windows.h>
void clrscr()
{
COORD coordScreen = { 0, 0 };
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsole, &csbi);
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten);
GetConsoleScreenBufferInfo(hConsole, &csbi);
FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten);
SetConsoleCursorPosition(hConsole, coordScreen);
}
#include <windows.h>
system("cls");
[QUOTE]Originally posted by Phoenix
#include <windows.h>
system("cls"); [/QUOTE
I must disagree with you on that, there is no need what so ever in including <windows.h> the system("cls"); will work anyway...
>>> system("cls");
... and then you should read the FAQ to find out why that is such a bad idea...
http://www.cprogramming.com/boardfaq.html#execs
... for example is one reason.
A Big Thanks to all that helped me out on my two problems..
and for those interested..i solved my clear screen problem really easy by simply using:
#include <stdlib.h>
system("cls")
it works perfectly you just put the system("cls") where ever you want the screen to clear..
thnx again..
kimmiej
"You can lead a horse to water.... "
Sorry for my relative lack of knowledge, but if you copied the header from Borland (conio.h) and overwrote Microsoft's would clrscr() work?
Well, considering as nowhere in the previous posts before mine does it confirm what compiler is being used, I thought my offer of clrscr(); was a good one, considering no mention of compilers was made.
Its a shame that you are not as clever as programmers as you are rude and ungratefull, maybee then, you wouldnt have had to post here in the first place.
If unregistered would like to continue this conversation then please repost here.
As for helping, I will now not continue to try.
If you are running Linux, use system("clear"). If you are using DOS, here's my favorite way. :D
cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\ n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
And that should be enought to clear the screen. :D
>>>
Its a shame that you are not as clever as programmers as you are rude and ungratefull, maybee then, you wouldnt have had to post here in the first place.
<<<
It is also a shame that so many people offer truly bad advice...
ahem...
for remarkable control over your textual display beyond your wildest dreams... tinker [safely, within 32K, which is 80 by 25 by 2] with 0xb800:0000...
Perhaps 'Adrianxw' would like to tell us all how and where to obtain the crystal ball he so obviously posesses. If he took time to study the posts before mine, he might just be able to work out (painful for him as it may be), that there were absolubtly no mentions of the users compiler.
Therefore their ungrateful response, deserved my critisism.
My response to writers of rude and ungrateful Emails that take up my valuble time to read and respond to, is this:
"If you can't say anything nice, don't say anything at all", something I learnt when I was 5!
See the moderators views on posts like the one sent in response to my help. Now, can we please get on with sorting out programming issues, instead of all this petty squabling.
Quote:
Perhaps 'Adrianxw' would like to tell us all how and where to obtain the crystal ball he so obviously posesses.
It can be purchased for $4.99 at the magic crystal ball shop or ordered on CD. ;)
I think the problem is solved. If you want to know how to clear the screen in about any environment possible, read theFAQ that's what it is for.
Sorry NV, I know you locked it, but I think there are a couple of important points to be made which Mr Ingleby doesn't seem to understand.
1. The FAQ is there to help people. Clearing the screen is probably the most frequently asked question on this, (and other), boards. Directing people to the FAQ is a service. There is a lot of good advice in the FAQ.
2. We now have a guy who can clear the screen with system(). Great, he is using the wrong tool. When his programs start to run too slowly, he will not understand why. The fact is, system() is bad advice.
Finally,
>>> that there were absolubtly no mentions of the users compiler.
... true, hence he should look in the FAQ. What is the point of suggesting a compiler specific method, when you don't know what compiler he is using?