3 Replies - 5318 Views - Last Post: 12 November 2009 - 10:18 PM Rate Topic: -----

#1 honumike  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 12-November 09

Source Code for determining water bill calculation

Posted 12 November 2009 - 08:37 PM

I have this code that is meant to determine how to charge a homeowner for a water bill by certain usage. The code is included and complies, but does not perform calculations. What am I not doing here? Code follows:

#include <iostream>
using namespace std;


void main()//should this be int main?
{
	int Amount;
	double Charge;
	cout << "Enter number of cubic feet \n ";
	cin >> Amount;
	cin. ignore();

	if (Amount <= 1000)// I had previously inserted braces after the ) and again after 15.00;
		Charge = 15.00;
	
	else (Amount <= 2000); // I had else if here at one point and it did not work
		Charge = .0175 * Amount;
	
	if (Amount <= 3000)
		Charge = .02 * Amount;
	
	else  Charge = 70.00; // There was a cin.get(); following this last else but it did not work

	
}



** Edit ** :code:

Is This A Good Question/Topic? 0
  • +

Replies To: Source Code for determining water bill calculation

#2 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5394
  • View blog
  • Posts: 27,388
  • Joined: 10-May 07

Re: Source Code for determining water bill calculation

Posted 12 November 2009 - 08:41 PM

View Posthonumike, on 12 Nov, 2009 - 09:37 PM, said:

void main()//should this be int main?


Yes. But you'll also need to give it a return type because you are declaring it to return int, & so it will then need to.

In your code above, you gather the users input, & you calculate it. But what do you want it to do from there?
Was This Post Helpful? 0
  • +
  • -

#3 honumike  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 12-November 09

Re: Source Code for determining water bill calculation

Posted 12 November 2009 - 09:13 PM

View Postno2pencil, on 12 Nov, 2009 - 07:41 PM, said:

View Posthonumike, on 12 Nov, 2009 - 09:37 PM, said:

void main()//should this be int main?


Yes. But you'll also need to give it a return type because you are declaring it to return int, & so it will then need to.

In your code above, you gather the users input, & you calculate it. But what do you want it to do from there?


I wan't it to tell me which method of billing will be appropriate. It will be one of the four listed. I had the main as "int" but it did not work either.
Was This Post Helpful? 0
  • +
  • -

#4 OliveOyl3471  Icon User is offline

  • Everybody's crazy but me!
  • member icon

Reputation: 134
  • View blog
  • Posts: 6,581
  • Joined: 11-July 07

Re: Source Code for determining water bill calculation

Posted 12 November 2009 - 10:18 PM

You want it to tell you...? You mean, you want something printed? Then you use cout:
#include <iostream>
using namespace std;


int main()//should this be int main?
{
	int Amount;
	double Charge;
	cout << "Enter number of cubic feet \n ";
	cin >> Amount;
	cin. ignore();

	if (Amount <= 1000)// I had previously inserted braces after the ) and again after 15.00;
		Charge = 15.00;
	
	else if (Amount <= 2000) // I had else if here at one point and it did not work 
//you were right to use else if, but remove the semicolon...and using curly braces {} is better 
//though it does work without them, as long as the else includes only one line
		Charge = .0175 * Amount;
	
	else if (Amount <= 3000)
		Charge = .02 * Amount;
	
	else  Charge = 70.00; // There was a cin.get(); following this last else but it did not work

	cout<<"Charge is: "<<Charge<<endl;
	system("Pause"); //pause to see output
	return 0; //because int main must return an int
}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1