I am trying to do an if/else problem.
User is asked to input if they have a meal plan.
User inputs a string "yes" or "no"
My problem is running the if/else to later calculate the cost of a meal plan if the answer yes = true.
I have this so far:
[CODE=cpp]const double MEAL_PLAN = 1245.00;
int num1 = 0;
string str1 = "yes"
string str2 = "no"
cout << " Please enter yes or no for meal plan: ";
cin >> str1, str2;
if ( str1 != str2){
meal_plan = true;
}
else
{
meal_plan = false;
}
cout << endl;
cout << "Meal Plan: " ;
if (meal_plan == true){
MEAL_PLAN; // to return cost of meal plan
}
else
{
num1; // to return 0
}[/CODE]
I am not sure if I can use the string in this. I am not getting it to calculate. I have tried using a different variable in cin, and still cannot get it to work.
Any ideas?
Thank you,
Suemez
User is asked to input if they have a meal plan.
User inputs a string "yes" or "no"
My problem is running the if/else to later calculate the cost of a meal plan if the answer yes = true.
I have this so far:
[CODE=cpp]const double MEAL_PLAN = 1245.00;
int num1 = 0;
string str1 = "yes"
string str2 = "no"
cout << " Please enter yes or no for meal plan: ";
cin >> str1, str2;
if ( str1 != str2){
meal_plan = true;
}
else
{
meal_plan = false;
}
cout << endl;
cout << "Meal Plan: " ;
if (meal_plan == true){
MEAL_PLAN; // to return cost of meal plan
}
else
{
num1; // to return 0
}[/CODE]
I am not sure if I can use the string in this. I am not getting it to calculate. I have tried using a different variable in cin, and still cannot get it to work.
Any ideas?
Thank you,
Suemez
Comment