I am a noob that is currently trying to learn C++ for a programming class in highschool, and I am having difficulty with a particular project. Basically, I have to create a number guessing game that lets the user play as many time as he or she wants, while telling him or her if the guess is too high or too low.
However, my if statements aren't working correctly in the loop, they both show up in the command box when the game is run. Furthermore, if I try to use an if else statement for the second condition, the first guess will always turn up as (greater than the number) and every subsequent one afterwards will be lower.
Again, thankyou for assistance if possible.
/* February 25th, 2008
Assignment #1 */
#include <iostream.h>
#include <stdlib.h> // For Randomization
#include <time.h> // For Randomization
#include "msoftcon.cpp" // External Application
void main()
{
// Setting Colours
init_graphics();
set_color(cGREEN,cBLACK);
srand (time(NULL)); // Starts the randomization process
char myname[31];
int guess;
int tries= 0;
int number= rand()% 10;
int choice;
cout<< " ---------------------------\n";
cout<< " |THE AMAZING GUESSING GAME|";
cout<< "\n ---------------------------";
cout<< "\n\nPlease enter your first name... ";
cin.get (myname, 20, '\n'); // Ends getting the name as enter is hit
do
{
do
{
cout<< "\n\nPlease enter a number (1-10): ";
cin>> guess; // Enter in a number
if (guess < 0 || guess>10)
{
cout<< "\nInvalid Value\n";
return;
}
if (guess< number, tries++)
{
cout<< "\nYour guess is a bit low...\n";
}
if (guess> number, tries++)
{
cout<< "\nYour guess is a bit high...\n";
}
cout<< "\nYou are on guess "<< tries;
} while (guess!= number); // Continue if [guess] is wrong
cout<< "\n\nYou have guessed the magic number "<< number<< ", in "<< tries<< " tries...";
cout<< "\n\n\nCongratulations "<< myname<< "!\n\n\n\n\n";
cout<< "\n\nPress 0 to quit, press any other number to replay: ";
cin>> choice;
} while (choice!= 0); // Replay if anything other than 0 or character is entered.
cout<< "Goodbye... ";
return;
}