Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.80 KB | None | 0 0
  1. //Objective:  generate an integer between 1 and 100, user guesses as to what number it is
  2. //Name: Phillip Yee
  3. //Course: COMSC-110-8215
  4. //Compiler: MS Visual Studio 2010
  5. //Editor: MS NotePad
  6.  
  7. //libraries
  8. #include <iostream>
  9. #include <cstdlib>
  10. #include <ctime>
  11.  
  12. using namespace std;
  13.  
  14. //Programmer defined data types
  15.  
  16. struct Guess
  17. {
  18.   int number;
  19.   Guess* next;
  20. };
  21.  
  22. //Special compiler dependent definitions
  23. //NONE
  24.  
  25. //global constants/variables
  26. //NONE
  27.  
  28. //Programmer defined functions
  29.  
  30. //main program
  31. int main()
  32. {
  33.   srand(time(0)); rand(); //seed
  34.  
  35.   // output my name and objective and program information
  36.   cout << "Objective: generate an integer between 1 and 100, user guesses as to what number it is\n";
  37.   cout << "Programmer: Phillip Yee\n";
  38.   cout << "Editor(s) used: Notepad\n";
  39.   cout << "Compiler(s) used: VC++ 2010 Express\n";
  40.   cout << "File: " << __FILE__ << endl;
  41.   cout << "Complied: " << __DATE__ << " at " << __TIME__ << endl << endl;
  42.  
  43.   //variables
  44.  
  45.  
  46.   int answer;
  47.   int aGuess;
  48.   answer = 1 + rand() % 100;
  49.  
  50.   //empty list
  51.   Guess* start = 0;
  52.  
  53.   while (true)
  54.   {
  55.   Guess* aGuess = new Guess;
  56.   cout << "Guess a number between 1 - 100:" << endl;
  57.   cin >> aGuess->number;
  58.   cin.ignore(1000, 10);
  59.  
  60.   aGuess->next = start;
  61.   start = aGuess;
  62.  
  63.         if (answer == aGuess->number) break;
  64.  
  65.         if (answer < aGuess->number)
  66.           cout << "Your guess is too high, try again:" << endl;
  67.  
  68.         if (answer > aGuess->number)
  69.           cout << "Your guess is too low, try again:" << endl;  
  70.  
  71.     Guess* p;
  72.     for (p = start; p; p = p->next)
  73.       {  
  74.      
  75.         if(aGuess->number == p->number)
  76.           cout << "You already guessed " << aGuess->number << ", try again:" << endl;
  77.        
  78.       }
  79.   }
  80.   cout << "You guessed right!";
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement