Thread: going crazy- codewarrior debugging, someone help me please.

  1. #1
    Unregistered
    Guest

    Angry going crazy- codewarrior debugging, someone help me please.

    this code for school is really really bugging me. these errors are confusing the hell out of me. someone please give me some help!! i use codewarrior learning edition.. not sure what version though, anyway here it is:

    // This program is used to compute the amount due from a
    // customer of the Gas-N-Clean Service Station. Constants
    // are used for gasoline prices. Note the use of nested
    // selection to compute the cost of the car wash.

    // Program file: gas.cpp

    #include <iostream.h>
    #include <iomanip.h>

    const double REGULAR_PRICE = 1.149;
    const double PLUS_PRICE = 1.199;
    const double SUPER_PRICE = 1.289;

    // Function: printHeading
    // Prints a signon message for program

    void printHeading();

    // Function: getData
    // Get information interactively from the keyboard.
    // Outputs: number of gallons purchased, type of gasoline
    // a choice as to whether a car wash is desired

    void getData(double &numGallons, char &gasType, char &washOption, char &washType);

    // Function: computeCharges
    // Computes the gas cost, wash cost, and total cost
    // Inputs: number of gallons, gas type, wash option
    // Outputs: gas cost, wash cost, total cost

    void computeCharges (double numGallons, char gasType, char washOption, double &gasCost, double &washCost, double &totalCost);

    // Function: printMessage
    // Prints a sign-off message for program

    void printMessage();

    // Function: printResults
    // Print the results
    //
    // Inputs: number of gallons purchased, type of gasoline,
    // gas cost, wash cost, total cost

    void printResults (double &numGallons, char &gasType, double &gasCost, double &washCost, double &totalCost);

    int main()

    {

    char gasType; //Type of gasoline purchased (R,P,S,N)
    char washOption; // Character designating option (Y,N)
    char washType; // Type of wash (S,D)
    double numGallons; // Number of gallons purchased
    double gasCost; // Computed cost for gasoline
    double washCost; // Car wash cost
    double totalCost; // Total amount due

    getData(numGallons, gasType, washOption, washType);
    computeCharges(numGallons, gasType, washOption, gasCost, washCost, totalCost);
    printResults(numGallons, gasType,
    gasCost, washCost, totalCost);

    return 0;

    }

    void printHeading()

    {

    cout<< setiosflags(ios::right) << endl;
    cout<< setw(55)
    << "****************************************"
    << endl;
    cout<< setw(55)
    << "* Gas-N-Clean Service Station *"
    << endl;
    cout<< setw(55)
    << "* *"
    << endl;
    cout<< setw(55)
    << "* July 25, 1997 *"
    << endl;
    cout<< setw(55)
    << "* *"
    << endl;
    cout<< setw(55)
    << "***************************************"
    << endl;
    cout<< endl;

    }

    void getData(double &numGallons, char &gasType, char &washOption, double &washType)

    {
    cout<< "Enter number of gallons and press <Enter>. ";
    cin>> numGallons;
    cout<< "Enter gas type (R, P, S, or N) and press <Enter>. ";
    cin>> gasType;
    cout<< "Enter Y or N for car wash and press <Enter>. ";
    cin>> washOption;
    cout<< "Enter either S (Standard) or D (Deluxe) and press <Enter>. ";
    cin>> washType;
    }

    void computeCharges(double numGallons, char gasType, char washOption, double &gasCost, double &washCost, double &totalCost, double &washType)

    {

    switch (gasType)

    {
    case 'R': gasCost = numGallons * REGULAR_PRICE;
    break;
    case 'P': gasCost = numGallons * PLUS_PRICE;
    break;
    case 'S': gasCost = numGallons * SUPER_PRICE;
    break;
    case 'N': gasCost = 0.0;
    }

    if (washOption == 'Y')
    if (washType == 'S')
    if (gasCost >= 10.0)
    washCost = 3.0;
    else
    washCost = 5.0;
    if (washOption =='Y')
    if (washType == 'D')
    if (gasCost >= 10.0)
    washCost = 6.0;
    else
    washCost = 8.0;
    totalCost = gasCost + washCost;

    }

    void printMessage()

    {
    cout << endl;
    cout << setw(48) << "Thank you for stopping" << endl;
    cout << endl;
    cout << setw(43) << "Please come again" << endl;
    cout << endl;
    cout << setw(55)
    << "Remember to buckle up and drive safely"
    << endl;
    cout << endl;

    }

    void printResults(double numGallons, char gasType, double gasCost, double washCost, double totalCost)

    {

    printHeading();
    cout << setiosflags(ios::fixed | ios::showpoint);
    cout << setw(43) << "Amount of gasoline purchased "<< setw(12) << setw(6) << setprecision(3) << numGallons << " Gallons" << endl;
    cout << setw(31) << "Price per gallon" << setw(22) << "$";
    switch (gasType)
    {
    case 'R': cout << setw(7) << REGULAR_PRICE <<endl;
    break;
    case 'P': cout << setw(7) << PLUS_PRICE <<endl;
    break;
    case 'S': cout << setw(7) << SUPER_PRICE <<endl;
    break;
    case 'N': cout << setw(7) << 0.0 <<endl;
    }
    cout << setw(34) << "Total gasoline cost"
    << setw(19) << "$"
    << setw(6) << setprecision(2) << gasCost
    << endl;
    if (washCost > 0)
    cout << setw(28) << "Car wash cost"
    << setw(25) << "$"
    << setw(6) << washCost << endl;
    cout << setw(31) << "Total due"
    << setw(22) << "$" << setw(6)
    << totalCost << endl;
    printMessage();
    }

    i just need the errors debugged, thats all. someone, anyone!

  2. #2
    Unregistered
    Guest

    I see a couple

    Ok, first of all, you never use your print heading function.


    Second, when you have compute charges input all the information and set it, you are setting all of your information to nonexistent variables because the ones in main go out of scope. Instead, try using pointers that point to ur variables and have the operations done on the pointers.

    Good Luck

  3. #3
    Unregistered
    Guest

    uhm...

    i don't want to sound so newbie, but i am, can you just give me an example as to what you mean for the second problem? thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Is AOL music crazy?
    By joeprogrammer in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 03-24-2006, 07:24 PM
  2. restart drives me crazy
    By Jumper in forum A Brief History of Cprogramming.com
    Replies: 20
    Last Post: 03-17-2004, 12:52 PM
  3. crazy
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 08-31-2002, 08:54 PM
  4. crazy output
    By asirep in forum C Programming
    Replies: 22
    Last Post: 04-09-2002, 11:41 AM
  5. Replies: 1
    Last Post: 02-24-2002, 06:24 PM