I am taking a C++ course, though I am far behind due to my inability to grasp the material. and i must complete 3 projects by Jan. 29. I am having ALOT of trouble implementing the switch statement, and I don't know how to make it loop back the user input should the input be default. Here is the criteria for the first project:
# Create a menu system that gives the user the option of seeing their fortune OR stock market advice.
# Use the same choices for your fortune as the project in Workshop 7.
# If the user chooses to get Stock Market advice, generate a random number that will help choose which advice to give. The options are:
* "You should definitely buy!"
* "Sell! Sell! Sell!"
* "Heck if I know. Go ask your stock broker."
# Make one function for the fortune teller option and another function for the Stock Market advice option.
# For the fortune teller function, use the if, if else syntax to write your function.
# For the stock advice option you should use the Switch statement to write your function.
# After the user has their results, the program should ask the user if they want to quit. If they want to quit, the program will end. If not, the program should display the menu again and let the user choose again. (*Hint: Use a function for your menu)
Here is the code I have so far:
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
int main()
{
char uChoice;
string sentence;
int iResult;
string iCompany;
cout<<"Welcome to the fortune teller."<<endl;
cout<<"You may enter the letter A to view your fortune, or B to see stock market advice."<<endl;
cin>> uChoice;
switch(uChoice) {
case 'A':
iResult = 1;
cout<<"You chose to view your fortune!";
break;
case 'B':
iResult = 2;
cout<<"You chose to view stock market advice!";
break;
default:
iResult = 0;
cout<<"You must enter A or B.";
break;
}
if (iResult = 1);
cout<< "Type in a yes or no question about your future."<<endl
cin>> sentence;
else if (iResult = 2)
cout<< "Enter a company with stock."<<endl
cin<< iCompany
else
cout<< "You must enter 1 or 2."<<endl
}
I know people don't like it when someone is just looking for an easy out on homework, but I am trying, I'm just a C++ noob. I would like to continue programming, but getting these projects done are my first priority.