gasBill.cpp

The times they are a-changin’.

This post seems to be older than 18 years—a long time on the internet. It might be outdated.

Here’s this week C++ project we had to do. I’m just going to post original work that I made, not files they had us fix.

//Name: Andrew Ferguson
//Date: 1/27/2005
//Purpose: Compute gas costs
#include <conio.h>
#include <iostream>
#include <stdio.h>

using namespace std;

int prevMonth, thisMonth, gasDiff;
double cost = 0;
char n;

int main(){
    cout << "Enter last months gas reading:";
    cin >> prevMonth;
    cout << "Enter this months gas reading:";
    cin >> thisMonth;
    if(thisMonth < prevMonth){
                 thisMonth += 10000;
                 }
    gasDiff = thisMonth - prevMonth;

    if(gasDiff <= 70){
               cost = 14.95;
               }
    else if(gasDiff <= 170){
         cost = gasDiff * 0.095;
         }
    else if(gasDiff <= 400){
         cost = gasDiff * 0.0525;
         }
    else{
         cost = gasDiff * 0.02125;
         }
    cout << "Your total gas bill for this month is: " << cost << endl;
    printf("Press any key to continue...");
    n = getch();

    return 0;
}

Download the compiled executable

0