#include <string>
using namespace std;
int main ()
{
int i, f, m;
string n;
double a = 2.60;
double b = 3.36;
double c = 2.79;
double t;
cout << "Initial meter reading:";
cin >> i;
cin.ignore(100000, '\n');
cout << "Final meter reading:";
cin >> f;
cin.ignore(100000, '\n');
int hcf = f - i;
cout << "Customer name:";
cin >> n;
cin.ignore(100000, '\n');
cout << "Month number (1=Jan, 2=Feb, etc.):";
cin >> m;
cin.ignore(100000, '\n');
if (m == 6 || 7 || 8 || 9 || 10)
{
if (hcf <= 46)
{
t = hcf * a;
}
else if (hcf > 46)
{
t = ((hcf - 46)*b) + 119.60;
}
}
else
{
if (hcf <= 32)
{
t = hcf * a;
}
else if (hcf > 32)
{
t = ((hcf - 32)*c) + 83.20;
}
}
cout << "---\nThe bill for " << n << " is $" << t << "\n";
}
The problem is in regards to the bolded part. I have the condition only if m is a number 6-10, but any number I input, it still uses the bold code block instead of going to the italicized else block. What am I doing wrong? And, how do I make it that in the underlined output, the number is always shown as a nonnegative number with at least one digit to the left and exactly two digits to the right of the decimal point?
Also, I'm not understanding too well why I don't get an error for using double, but I do for float. I thought float could be used for decimals too.
Please point out any mistakes in the code or anything that is not needed yet included in there. Thanks in advance.
Edited by finalcloud13, 17 October 2007 - 04:23 AM.