int main()
{
int guessNum, randNum;
for ( ; ; )
{
randNum = genRandNum(); //genRandNum is a function I made for generating a random number
printf( "Enter your guess.\n\n" );
scanf( "%d", &guessNum);
if (guessNum == randNum)
{
printf( "Woohoo. You guessed correctly!" );
Sleep(2000);
break;
} //end if
else
{
printf( "The number you entered is not correct. Please try again.\n\n" );
Sleep(2000);
system("CLS"); //this clears the console screen
} //end else
} //end for
return 0;
} //end main
\c++\1\main.cpp||In function 'int main()':| \c++\1\main.cpp|17|error: 'Sleep' was not declared in this scope| \c++\1\main.cpp|18|error: break statement not within loop or switch| ||=== Build finished: 2 errors, 0 warnings (0 minutes, 0 seconds) ===|
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
using namespace std;
int main()
{
printf("Guess the number from 0 to 15");
int x;
int guess;
x = rand() % 15 + 1;
cin >> guess;
if (guess == x) printf("Correct");
else if (guess < x) printf("Your guess is too low");
else if (guess > x) { printf("Your guess is too high");
Sleep(1500);
break;
}
return 0;
}
#include <windows.h>
#include <iostream>
using namespace std;
int main()
{
for ( ; ; )
{
cout << "Guess a number from 0 to 15" << endl;
int guess;
int x = rand() % 15 + 1;
cin >> guess;
if (guess == x)
{
cout << "Your guess was correct!" << endl;
Sleep(2000);
break;
} //end if
else if (guess < x)
{
cout << "The number " << x << endl;
cout << "Your guess was too low!" << endl;
Sleep(2000);
system("ClS");
} //end if
else
{
cout << "The number was " << x << endl;
cout << "Your guess was too high" << endl;
Sleep(2000);
system("CLS");
} //end else
} //end for
return 0;
} //end main
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\..\..\..\..\include\windef.h||In function 'int main()':| c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\..\..\..\..\include\windef.h|8|error: expected unqualified-id before string constant| c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\..\..\..\..\include\winnt.h|2444|error: expected '}' before end of line| c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\..\..\..\..\include\winnt.h|2444|error: expected declaration before end of line| ||=== Build finished: 3 errors, 0 warnings (0 minutes, 0 seconds) ===|
#include <cstdlib>
#include <iostream>
#include <limits>
#include <ctime>
int main() {
std::srand(std::time(0));
int x = std::rand() % 16;
int guess;
while ( (std::cout << "Guess the number between 0 and 15: ") &&
(!(std::cin >> guess) || (guess != x)) ) {
std::cout << "That's not right!" << std::endl;
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
std::cout << "That's right! The number is " << x << '.';
}