• ## Discover

1. Home >
2. All Categories >
3. Computers & Internet >
4. Programming & Design >
5. Resolved Question
Member since:
March 30, 2006
Total points:
2,155 (Level 3)

## Resolved Question

Show me another »

# How to Write a C++ program to Calculate the Cost of This?

Write a c++ program to calculate the cost of a visit to a gas station. The program should ask the user whether he or she wants regular (2.629\$ per gallon) or premium (2.979\$ per gallon) of gasoline, whether or not a car wash is desired. Of course the program must also ask how many gallons it took to fill the tank. Then the program should calculate the cost of the gas and the total cost including a car wash if there was one. Help me please, Thank You!
by chris
Member since:
June 27, 2009
Total points:
181 (Level 1)

double x, g;
char y;

cout<<"Press 1 for regular 2 for premium."<<endl;
cin>>x;
cout<<"would you like a car wash? y/n?"<<endl;
cin>>y;
cout<<"How many gallons to fill your tank?"<<endl;
cin>>g;

if ( x = 1 ) {
x = g * 2.629;
} else {
x = g * 2.979;

if ( y = "y" ) {
x = x + whatever car wash costs
}

• 2 people rated this as good
Thank You!

There are currently no comments for this question.

• by Luja
Member since:
September 25, 2009
Total points:
156 (Level 1)
#include<iostream.h>
#include<conio.h>
main()
{
int type;
float typecost[]={2.629,2.979};
float carwashcost=0;
int carwash;
int noofgallons;
float totalcost;

cout<<"Enter Type:\n1-Regular (2.629\$ per gallon)\n2-Premium (2.979\$ per gallon)\n";
cin>>type;
cout<<"Number of gallons:";
cin>>noofgallons;
cout<<"Desire Car Wash:\n1-Yes \n2-No\n";
cin>>carwash;
if (carwash==1)
{
cout<<"Cost for Car Wash:\n";
cin>>carwashcost;
}
totalcost = (typecost[type-1]*noofgallons) + carwashcost;
cout<<"Total cost for gas is "<<(typecost[type-1]*noofgallons)<<" and total cost for the service is "<<totalcost;
getche();
}
• 1 person rated this as good