Ok, I'm trying to use a 'switch' statement, but with two possible scenarios for one of the switches. If the time is greater than 1min, I want it to output the time in mins. If it is 1min or less, I want it to output the time in secs. Everything else in my program is going the way I want it to. Can someone help me out here? Oh, bear with me on the words. I like to entertain myself while I learn this.
int main ()
{
cout<<"Enter a dollar amount to convert into equivalent currency.\n";
int dollars;
cin>>dollars;
cout<<"Now choose a conversion type by entering the appropriate number for your selection.\n";
cout<<"1. Dirt (in kgs.)\n";
cout<<"2. Punches to face.\n";
cout<<"3. Time in ring with starving grizzly bear.\n";
char convert;
cin>>convert;
switch (convert) {
case'1':
cout<<"$"<<dollars<<" = "<<dollars*1.5<<"kgs.";
break;
case'2':
cout<<"$"<<dollars<<" = "<<dollars*2.5<<" punches.";
break;
case'3':
if (dollars>1)
cout<<"$"<<dollars<<" = "<<dollars*0.2<<"mins. of fun.";
else (dollars<=1)
cout<<"$"<<dollars<<" = "<<dollars*0.2*60<<"secs. of fun.";
default:
cout<<"Wow, you must be as dumb as a stump.";
cout<<"Try entering one of the given numbers next time.";
break;
}
}
#include <iostream>
using std::cout;
using std::cin;
int main ()
{
cout<<"Enter a dollar amount to convert into equivalent currency.\n";
int dollars;
cin>>dollars;
cout<<"Now choose a conversion type by entering the appropriate number for your selection.\n";
cout<<"1. Dirt (in kgs.)\n";
cout<<"2. Punches to face.\n";
cout<<"3. Time in ring with starving grizzly bear.\n";
char convert;
cin>>convert;
switch (convert) {
case'1':
cout<<"$"<<dollars<<" = "<<dollars*1.5<<"kgs.";
break;
case'2':
cout<<"$"<<dollars<<" = "<<dollars*2.5<<" punches.";
break;
case'3':
if (dollars>1)
cout<<"$"<<dollars<<" = "<<dollars*0.2<<"mins. of fun.";
elseif (dollars<=1) //or just else
cout<<"$"<<dollars<<" = "<<dollars*0.2*60<<"secs. of fun.";
break;
default:
cout<<"Wow, you must be as dumb as a stump.";
cout<<"Try entering one of the given numbers next time.";
break;
}
}
Though you could also simply use an else instead of else if. Because if it is not greater than 1 it must be less than or equal to 1.
You are also missing a break in case 3. So default will always be called.