HELP - New to C++ and most other programming
The program I wrote below is supposed to play a guessing game based on the computer picking a random letter. All it does is loop twice then say you win. Also the if higher/lower portion is not processing properly. eg: (depending on if the if statement is guess < randomLetter) guess a - the letter is lower, guess a - You win. I have spent hours looking thru this site and others for help for most of my problems but I generally can't find the answer I need or am just so C++ disabled I can't see the answer in front of me.
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
//declaration of variables
int number = 0;
string letters = "abcdefghijklmnopqrstuvwxyz";
string randomLetter = "";
string guess = "";
//initialize the random number generator
srand(time(NULL));
//assign a the random value to number
number = 0 + rand() % (26 - 10 + 1);
//find the letter that coresponds to the number
randomLetter.assign(letters, number, 0);
//get users guess
cout << "The computer has secretly picked a letter." << endl;
cout << "Try to guess the letter." << endl;
cout << "Your guess is: ";
getline(cin, guess);
transform(guess.begin(), guess.end(), guess.begin(), tolower);
// verify that user entered only one letter
if (guess.size() == 1)
{
//repeat code till users guess is correct
while (guess != randomLetter)
{
//display higher or lower clue
if (guess < randomLetter)
cout << "The letter you are looking for is lower in the alphabet." << endl;
else
cout << "The letter you are looking for is higher in the alphabet." << endl;
//end ifs
cout << "Please try again!" << endl;
cout << "Your guess is: ";
getline(cin, guess);
transform(guess.begin(), guess.end(), guess.begin(), tolower);
}//end while
cout << "That is correct!" << endl;
cout << " YOU WIN !!! " << endl;
}
else
cout << "Please enter one letter only.";
return 0;
}// end of main function