Objective - To write a program that will predict the future
Method - 1. Use the main procedure to
a. Prompt the user for his/her lucky number. Use this number as input to the srand function found in cstdlib
b. Prompt the user for which life topic he wishes his predictions based. Based on the user's response call one of three functions. Suggestions are love, finance, and school, but you may use three of your own choosing. Use a nested if-else statement to control which function is called.
2. Each function will
c. Call the rand function
d. Use value generated by the rand function and modulo division as the selector expression in a switch statement.
e. The switch statement will print out the predictions.
f. Allow for five different predictions per function.
3. Prompt the user to see if they want another prediction. Keep executing the program until the user tells you to quit. Make sure that you code for all possible user inputs, including wrong ones.
Hand In -
1. A copy of your program
2. A copy of the output. As the output scrolls past the black box, keep selecting the output and pasting it into the text editor as you go. Make sure that the output shows that your program will work under all possible scenarios. You may have to run the program more than once to do this.
Extra Credit: Print the, "I am looking into my crystal ball." statement. Then print the "hour glass" as in the demo version. Hint use the clock( ) function in the ctime library,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
|
#include <iostream>
#include <cstdlib>
#include <string>
#include <ctime>
using namespace std;
void choice();
void finance();
void health();
void love();
int main()
{
int lucknum;
char x;
bool userFails =true;
cout << "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *" << endl;
cout << "* *" << endl;
cout << "* Welcome to the Psychic Computer Network. *" << endl;
cout << "* My name is David, and I will be your psychic computer guide. *" << endl;
cout << "* *" << endl;
cout << "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *" << endl << endl;
cout << "Please enter your lucky number: ";
cin >> lucknum;
srand(lucknum);
cout << endl;
choice();
do//do-while loop as in do you want to read another prediction?
{
cout << "\n\nThank you for using the psychic computer network.";
cout << "\nWould you like me to make another prediction? y for yes or n for no." << endl << endl;
cout << "Enter here: ";
cin >> x;
if (x == 'y' || x == 'Y')
{
cout << endl << endl;
choice();
}
else if (x == 'n' || x == 'N')
{
userFails = false;
break;
}
else
cout << "\n " << x << " is not y, n ,Y or N. Please only enter y, n, Y or N."; //let user know what he/she did wrong
userFails = true;
} while (userFails);
return 0;
}
void choice (void)
{
char choice;
bool userfails = true;
do
{
cout << "Please enter an \"F\" for my predictions on your Financial Situation."<< endl;
cout << "Please enter an \"L\" for my predictions on your Love Life." << endl;
cout << "Please enter an \"H\" for my predictions on your Health." << endl;
cout << endl;
cout << "Enter here: \n";
cin >> choice;
cout << "I am looking into my crystal ball." << endl;
cout << "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" << endl;
if (choice == 'F' || choice == 'f')
{
finance();
userfails = false; //without this the loop will start over again
}
else if (choice == 'L' || choice == 'l')
{
love();
userfails = false;//without this the loop will start over again
}
else if (choice == 'H' || choice == 'h')
{
health();
userfails = false;//without this the loop will start over again
}
else
{
userfails = true;//cant be too safe
}
}while (userfails);//repeat loop while user keeps failing
}
void finance(void)
{
int x = rand() % 5 + 1;
switch (x)
{
case 1:
cout << "You will be very rich.";
break;
case 2:
cout << "Times are tough but you will find your way.";
break;
case 3:
cout << "Saving is the key to your success. ";
break;
case 4:
cout << "Invest your money and the profit will be great. ";
break;
case 5:
cout << "You will be very poor. ";
break;
}
}
void love(void)
{
int x = rand() % 5 + 1;
switch (x)
{
case 1:
cout << "Be patient, you will find your perfect match.";
break;
case 2:
cout << "Nobody likes you.";
break;
case 3:
cout << "You will have to choose between two.";
break;
case 4:
cout << "You will find love very soon. ";
break;
case 5:
cout << "Your current partner is cheating on you.";
break;
}
}
void health(void)
{
int x = rand() % 5 + 1;
switch (x)
{
case 1:
cout << "You will live a long and healthy life";
break;
case 2:
cout << "You need to start going to the gym.";
break;
case 3:
cout << "Eat less junk food and start eating healthy.";
break;
case 4:
cout << "Your health will begin to deter.";
break;
case 5:
cout << "You will die soon";
break;
}
}
| |
I need help with the extra credit part. How do i use the clock function to print an hour glass?