Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Objective: generate an integer between 1 and 100, user guesses as to what number it is
- //Name: Phillip Yee
- //Course: COMSC-110-8215
- //Compiler: MS Visual Studio 2010
- //Editor: MS NotePad
- //libraries
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- //Programmer defined data types
- struct Guess
- {
- int number;
- Guess* next;
- };
- //Special compiler dependent definitions
- //NONE
- //global constants/variables
- //NONE
- //Programmer defined functions
- //main program
- int main()
- {
- srand(time(0)); rand(); //seed
- // output my name and objective and program information
- cout << "Objective: generate an integer between 1 and 100, user guesses as to what number it is\n";
- cout << "Programmer: Phillip Yee\n";
- cout << "Editor(s) used: Notepad\n";
- cout << "Compiler(s) used: VC++ 2010 Express\n";
- cout << "File: " << __FILE__ << endl;
- cout << "Complied: " << __DATE__ << " at " << __TIME__ << endl << endl;
- //variables
- int answer;
- int aGuess;
- answer = 1 + rand() % 100;
- //empty list
- Guess* start = 0;
- while (true)
- {
- Guess* aGuess = new Guess;
- cout << "Guess a number between 1 - 100:" << endl;
- cin >> aGuess->number;
- cin.ignore(1000, 10);
- aGuess->next = start;
- start = aGuess;
- if (answer == aGuess->number) break;
- if (answer < aGuess->number)
- cout << "Your guess is too high, try again:" << endl;
- if (answer > aGuess->number)
- cout << "Your guess is too low, try again:" << endl;
- Guess* p;
- for (p = start; p; p = p->next)
- {
- if(aGuess->number == p->number)
- cout << "You already guessed " << aGuess->number << ", try again:" << endl;
- }
- }
- cout << "You guessed right!";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement