1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
#include <iostream>
using namespace std;
#include <iostream>
using namespace std;
int main()
{
/* int lowerbound = 1; //im not sure, but i think using const int here rapes the whole iteration later on
int upperbound = 100; //also there's no need to use them in the global scope, so just declare them here*/
int Min = 1, Max=100, guess, feedback, plyrNum;
int turn=0, plyrW=0,plyrL=0, numGames=0; //you can put all these declarations in one or 2 lines ;)
//also you declare turn a lot of times, everytime using another variable for it, try avoiding this :)
char play;
cout<<"\n\n\n Welcome to the Guessing Game\n\n\n"; //using \n is faster
cout<<"INSTRUCTIONS: \n\n";
cout << " Enter an integer in the range 1 to 100.\n";
cout << "I will try to guess your number with in 6 guesses.\n";
cout << "If I can guess your number in 6 guesses, I Win!.\n";
cout << " If you pick a number I don't guess, You Win!.\n\n";
cout << " Would you like to play?\n";
cout << " press 'Y' to play, or 'N' to quit: \n\n";
cin >> play;
cout << "\n\n";
while(play!='n'||play!='N'){
cout << "\n";
cout << "Games played: " << numGames << "\n";
cout << "Player Wins: " << plyrW << "\n";
cout << "Player Lost: " << plyrL <<"\n\n";
cout << "enter an integer from 1 to 100: ";
cin >> plyrNum;
cout <<"\n";
for(int turn=0; turn<7 && feedback !='c'; ++turn)//using a for loop here, making it <7 so it can do the if statement
{
guess = (Min + Max)/2;
cout << "turn number: " << turn <<"\n\n";
cout << "My guess is " << guess << "\n\n";
cout <<"is guess low (l), high (h), or correct (c)?"<<"\n";
cin >> feedback;
if (feedback == 'l') {
Min = guess + 1;
}
else if (feedback == 'h') { //use else if here ;)
Max = guess - 1;
}
else if (feedback == 'c') {
int plyrL = plyrL + 1;
}
}
if (int turn = 6) {
int plyrW = plyrW+ 1;
}
int numGames = numGames + 1;
cout << "would you like to play again?\n ";
cin >> play;
}
cout << "good bye!\n"; //don't need an if statement here, since the program'll only come here if play!=Y
return 0;
}
|