A
arnuld
My friend sent me the prototype of a game written in C++ and asked for
advice:
IDEA: Game will ask the user to thin of a number. User will press a
keystroke after he has thought of a number. Then program will ask him to
do some little arithmetic and will finally ask for the result. It will
then print what user has thought of.
Here is what I finished with. Any advice is appreciated
#include<iostream>
int main()
{
const int think_time = 5;
std::cout << std::endl;
std::cout << "<<<<<<< Let's play a Game >>>>>>\n" << std::endl;
std::cout << "\tThink of a number between 1 to 9\n"
<< "\tPress Ctrl-D when you are done";
char ch;
while( std::cin >> ch )
{
continue;
}
std::cout << std::endl << std::endl;
std::cout << "\t*Add 10 to that number\n";
sleep(think_time);
std::cout << "\t*Now subtract 5 from it\n";
sleep(think_time);
std::cout << "\t*Add another 20 to it\n";
sleep(think_time);
std::cout << "\t*Subtract 7 from it\n";
sleep(think_time);
std::cout << "\t*Subtract 3 from it\n";
sleep(think_time);
std::cin.clear();
std::cout <<"\tHow Much U Have Now :- ";
int think_num;
std::cin >> think_num;
int result = think_num - 15;
if(result < 0)
{
result = -(result);
}
std::cout <<".....Number you thought is :- "
<< result
<< std::endl;
return 0;
}
advice:
IDEA: Game will ask the user to thin of a number. User will press a
keystroke after he has thought of a number. Then program will ask him to
do some little arithmetic and will finally ask for the result. It will
then print what user has thought of.
Here is what I finished with. Any advice is appreciated
#include<iostream>
int main()
{
const int think_time = 5;
std::cout << std::endl;
std::cout << "<<<<<<< Let's play a Game >>>>>>\n" << std::endl;
std::cout << "\tThink of a number between 1 to 9\n"
<< "\tPress Ctrl-D when you are done";
char ch;
while( std::cin >> ch )
{
continue;
}
std::cout << std::endl << std::endl;
std::cout << "\t*Add 10 to that number\n";
sleep(think_time);
std::cout << "\t*Now subtract 5 from it\n";
sleep(think_time);
std::cout << "\t*Add another 20 to it\n";
sleep(think_time);
std::cout << "\t*Subtract 7 from it\n";
sleep(think_time);
std::cout << "\t*Subtract 3 from it\n";
sleep(think_time);
std::cin.clear();
std::cout <<"\tHow Much U Have Now :- ";
int think_num;
std::cin >> think_num;
int result = think_num - 15;
if(result < 0)
{
result = -(result);
}
std::cout <<".....Number you thought is :- "
<< result
<< std::endl;
return 0;
}