Originally Posted by
dwks
I guess you could use something like this.
Code:
int a;
if(x > y) a = 1;
else a = 2;
switch(a) {
case 1:
std:cout << "x > y";
break;
case 2:
std:cout << "x <= y";
break;
}
Of course, I don't really see the point. It's basically the same thing as this:
Code:
if(x > y) std:cout << "x > y";
else std:cout << "x <= y";
[edit] Thinking about it, I think what you're looking for is the "else" statement. An else statement can follow any if. If the if's condition is false, the else clause is executed. You can combine them, too.
Code:
if(x > y) this();
else if(x < y) that();
else { // x == y
equal();
}
http://www.cprogramming.com/tutorial/lesson2.html [/edit]
Here, I'll just post what I have so far, with the problem I have commented out.. maybe that will be easier for to explain.
Code:
#include <cstdlib>
#include <iostream>
#include <iomanip>
using namespace std;
int main(int argc, char *argv[])
{
float time, minutes, remainder, rate, total;
cout << "Enter start time: " << endl;
cin >> setprecision(2) >> time;
remainder = time - static_cast<int>(time);
if (time > 0 && time < 23.6) // <-------------- need to make sure time is > 0 < 24
if (remainder < 0.6)
{
cout << "enter minutes: ";
cin >> minutes;
if (minutes > 0 && minutes < 601)
cout << endl << "Thank you. " << endl;
else
cout << "Number must be between 1 and 600";
if (time > 0 && time < 7.00)
rate = 0.12;
else if (time > 6.59 && time <= 19.00)
rate = 0.55;
else if (time > 19.00 && time < 24.00)
rate = 0.35;
total = minutes * rate;
cout << setprecision(2) << fixed << showpoint << endl;
cout << "Your total is: $" << total << endl;
}
else
cout << "Invalid number, try again";
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
system("PAUSE");
return EXIT_SUCCESS;
}