gasBill.cpp

28 Jan 2005 @19:34

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


Actions

Informations

Leave a comment

You can use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Code: To include code, bracket it with [code language="php"] and [/code].
Example: [code language="php"] echo "Hello, World!"; [/code]

Plugin Help: If your requesting help about a plugin, please provide as much information as possible. At the very least, include your WordPress Version and the Plugin Version!