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
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....
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...
This funtion is not supported in Microsoft visual C++.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 earlierWINDOWS 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");