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

Follow
  • Follow publicly
  • Follow privately
  • Unfollow
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 ...show more
Best AnswerAsker's Choice
  • chris answered 5 years ago
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
}

cout<<"your total is: "<<x<<endl;

Asker's rating & comment

4 out of 5
Thank You!
  • 2
  • Comment

Other Answers (1)

  • Luja answered 5 years ago
    #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
    • Comment
  • Sign In 

    to add your answer

Who is following this question?

    %
    BEST ANSWERS
    Member Since:
    Points: Points: Level
    Total Answers:
    Points this week:
    Follow
     
    Unfollow
     
    Block
     
    Unblock