UMD wants you to write a program that will prompt a user for their account numbe
ID: 3623367 • Letter: U
Question
UMD wants you to write a program that will prompt a user for their account number (int), the billing code (char), and the number of gallons used (float). If the user inputs an invalid code or a negative amount of gallons used, the output should display an error message. After the total cost calculation is made, the program should output the user's account number, billing code, gallons used, and total cost.I started the program but having problems with it can you help need to have done by Monday2/14.
Here is what I done:
//Header file
#include <iostream>
#include <iomanip>
using namespace std
//function main begins execution of program
int main ()
if ((useCode = 'C' || 'c') && (gallons <= 4000000);
Else if ((useCode == 'C' || useCode == 'c') && (gallons <= (float)4000000))
float computeBill(char, float);
{
int accountNo;
char useCode;
float gallons;
float amountDue;
cout << "Please enter your account number: ";
cin >> accountNo;
cout << "Please enter your use code - enter H for home, C for commercial, or I for industrial: ";
cin >> useCode;
cout << "Please enter the number of gallons you used: ";
cin >> gallons;
cout << "Account Number: " << accountNo << endl;
cout << "Use Code: " << useCode << endl;
cout << "Gallons Used: " << gallons << endl;
cout << "Amount Due: " << amountDue << endl;
{
if ((useCode == 'C' || 'c') && (gallons <= 4000000))
return 1000.00;
}
if (useCode = 'C' || 'c' && gallons > 4000000)
{
return ((gallons - 4000000) * .00025) + 1000;
}
If (useCode == 'I' || 'i' && gallons <= 4000000)
{
return 1000.00;
}
if (useCode == 'I' || 'i' && 4000000 < gallons <= 10000000)
{
return 2000.00;
}
if ((useCode == 'I' || 'i') && (gallons > 10000000))
{
return 3000.00;
Explanation / Answer
please rate - thanks
corrected version
after receiving your message--tried to keep it true to your code
//Header file
#include <iostream>
#include <iomanip>
using namespace std;
float computeBill(char, float);
//function main begins execution of program
int main ()
{
int accountNo;
char useCode;
float gallons;
float amountDue;
cout << "Please enter your account number: ";
cin >> accountNo;
cout << "Please enter your use code - enter H for home, C for commercial, or I for industrial: ";
cin >> useCode;
while(useCode!='H'&&useCode!='h'&&useCode!='c'&&useCode!='C'&&useCode!='I'&&useCode!='i')
{cout<<"must be H, I, or C ";
cout << "Please enter your use code - enter H for home, C for commercial, or I for industrial: ";
cin >> useCode;
}
cout << "Please enter the number of gallons you used: ";
cin >> gallons;
while(gallons<0)
{cout<<"Must be >=0 ";
cout << "Please enter the number of gallons you used: ";
cin >> gallons;
}
amountDue= computeBill(useCode,gallons);
cout << "Account Number: " << accountNo << endl;
cout << "Use Code: " << useCode << endl;
cout << "Gallons Used: " <<setprecision(2)<<fixed<< gallons << endl;
cout << "Amount Due: $" <<setprecision(2)<<fixed<<amountDue << endl;
system("pause");
return 0;
}
float computeBill(char useCode,float gallons)
{if(useCode=='h'||useCode=='H')
return 7.5+gallons*.0025;
else if (useCode == 'C' ||useCode == 'c')
if(gallons <= 2000000)
return 1000.00;
else
return 1000+(gallons-2000000)*.005;
else
if ( gallons <= 4000000)
return 1000.00;
else if (gallons <= 10000000)
return 2500.00;
else
return 4000.00;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.