Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstdlib>
- #include<ctime>
- using namespace std;
- int main()
- {
- //declare variables named answer that holds text
- char answer;
- //declares a variable named randomNumber that holds whole numbers
- int randomNum;
- //declares a variable named lowRange that holds whole numbers and initializes it to 0
- int lowRange = 0;
- //declares a variable named highRange thath holds whole numbers and initializes to 4
- int highRange = 4;
- //seeds the random number generator using expression 1)
- srand(static_cast<int>(time(NULL)));
- // promts the user to enter a question
- cout << "Ask the Magic 8 Ball a question: ";
- //ignores the user input
- //calls function randNumGen(highRange, lowRange) to generate a random number
- randomNum = (rand() % (highRange - lowRange + 1)) + lowRange;
- cout << "Part A Solution";
- if (randomNum == 0)
- cout << "Answer: Yes";
- else if (randomNum == 1)
- cout << "Answer: Maybe";
- else if (randomNum == 2)
- cout << "Answer: No";
- else if (randomNum == 3)
- cout << "Answer: Ask again late";
- else if (randomNum == 4)
- cout << "Answer: I don't know";
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement