Advertisement
crystalballin

Magic 8 Ball

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