Advertisement
crystalballin

Magic 8 Ball

Feb 22nd, 2018
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1.  
  2. #include<iostream>
  3. #include<cstdlib>
  4. #include<ctime>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.  
  10. //declare variables named answer that holds text
  11.  
  12.     char answer;
  13.  
  14. //declares a variable named randomNumber that holds whole numbers
  15.  
  16.     int randomNum;
  17.  
  18. //declares a variable named lowRange that holds whole numbers and initializes it to 0
  19.  
  20.     int lowRange = 0;
  21.  
  22. //declares a variable named highRange thath holds whole numbers and initializes to 4
  23.  
  24.     int highRange = 4;
  25.  
  26. //seeds the random number generator using expression 1)
  27.  
  28.     srand(static_cast<int>(time(NULL)));
  29. // promts the user to enter a question
  30.  
  31.     cout << "Ask the Magic 8 Ball a question: ";
  32.      
  33.  
  34. //ignores the user input
  35. //calls function randNumGen(highRange, lowRange) to generate a random number
  36.    
  37.         randomNum = (rand() % (highRange - lowRange + 1)) + lowRange;
  38.  
  39.    
  40.  
  41.     cout << "Part A Solution";
  42.      
  43.     if (randomNum == 0)
  44.         cout << "Answer: Yes";
  45.  
  46.     else if (randomNum == 1)
  47.         cout << "Answer: Maybe";
  48.     else if (randomNum == 2)
  49.         cout << "Answer: No";
  50.     else if (randomNum == 3)
  51.         cout << "Answer:  Ask again late";
  52.     else if (randomNum == 4)
  53.         cout << "Answer: I don't know";
  54.  
  55.  
  56.  
  57.     system("pause");
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement