Beginner Program

Pages: 12
Hmm, I'm not too sure why that would be the case. Maybe post your entire code so I can see.
You still have to address the fact that the first 1000 gallons of water are effectively included within the base fee for water for most of the customer types. You'll have to do something like: (0.01 * (gallons-1000)) but you'll still need to come up with some way of doing it so that if the customer used less than 1000 gallons that it won't start subtracting money from the base rate.

And yea it's fine. It wasn't that long ago that I was in the exact same position as you are know. I know how much someone helping on these forums can mean when your really bashing your head off the wall.

Meerkat
Last edited on
I forgot all about that, but here's my code thus far.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;


int main () 
{
    
    double gallons;
    string name;
    cout << "Please enter full name: ";
    getline (cin,name);
    string customerType;
cout <<"What type of customer are you?" << endl
  <<"Enter \"R\" for residential customers, \"B\" for business customers," << endl 
  <<"\"G\" for government or \"NP\" for non-profit customers." << endl;
getline (cin,customerType);
   cout<<"Enter Gallons :";
    cin>>gallons;
    float amountDue, waterbaseFee, wusageFee, sewagebaseFee, susageFee;
    if(customerType == "R" || customerType =="r"){ 
        amountDue = (15 + (0.02 * gallons));
}else if(customerType == "B" || customerType =="b"){
	amountDue = (25 + (0.03 * gallons));
}else if(customerType == "G" || customerType =="g" || customerType == "NP" || customerType =="np"){
	amountDue = (5 + (0.01 * gallons));
}else{
	cout << "incorrect input";

}
cout << "The base water fee is: " <<  setw(2)<< waterbaseFee << endl;
cout << "The water usage fee is: " << setw(2)<< wusageFee << endl;
cout << "The base sewage fee is: " << setw(2)<< sewagebaseFee << endl;
cout << "The sewer usage fee is: " << setw(2)<< susageFee << endl;
cout << "The total amount that you must pay for your water usage is: " << setfill('0') << setw(2)<< amountDue << endl;
    
  
    
    
system("pause");
    return 0;

}
At no point do you set the values of waterbaseFee, wusageFee, sewagebaseFee and susageFee. Because these values will be differnet depending on what type of customer it is, within each if statement you will have to set them

1
2
3
4
5
if(customerType == "R" || customerType =="r"){ 
        amountDue = (15 + (0.02 * gallons));
        waterbaseFee = //whatever
        //etc
}

Hope that makes sense to you.

Also make sure to use both setfill and setw for each cout.

Meerkat
Topic archived. No new replies allowed.
Pages: 12