#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0

    Newby needs help with simple program


    Trying to write a program where it calculates the cost of a car with a selected option package. 4 hours into it and I am about to go insane. Here's that assignment:

    Input a base price
    Input an option package code (2 letter code)
    Subtotal
    Apply 15% tax
    Attach package code to a package name
    Display package name and total price

    use loops, parallel arrays
    No functions

    Is anyone interested in helping me? Below is my code so far, which doesn't get me far.

    #include <iostream>
    #include <iomanip>
    #include <string>
    using namespace std;

    int main()
    {

    //Declare arrays and variables
    char optionPackageCodeArray [5] = {'BB','SP','NP','HE','UC'};
    double packageCostArray [5] = {1500,3250,4575,7500,5220};
    string packageNameArray [5] = {'Base','Sport','Intermediate level','Luxury','User Specified'};

    double basePrice = 0.0;
    double packageCost = 0.0;
    double subTotal = 0.0;
    double taxCost = 0.0;
    double totalCost = 0.0;
    char packageName = ' ';
    char optionPackageCode = ' ';
    char searchIndex = ' ';
    int sub = 0;

    //Prompt user for base price and option code
    cout<<"Enter the Base Price: $";
    cin>> basePrice;
    cout<<"Enter the Option Code:";
    cin>>optionPackageCode;


    //Find the optionPackageCode
    while (sub < 5 && optionPackageCodeArray[sub] != optionPackageCode)
    sub +=1;
    //end while

    //Associate the optionPackageCode with the packageCost
    if (sub < 5)
    cout << "Option Cost is: $" <<packageCost[sub]<<endl;
    else
    cout << "Invalid Code" <<endl;
    //end if


    subTotal = basePrice + packageCost;
    totalCost = subTotal * 1.15;

    //Display total cost of car with options and tax
    cout<<endl;
    for(char displayIndex = 0; displayIndex <5; displayIndex++)
    cout<<"Your final cost with the "<<packageName<<" is: $"<<totalCost<<endl;

    system("pause");
    return 0;
    } //end of main
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    71
    Rep Power
    3
    So what are you having problems with? Well besides C++.
  4. #3
  5. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,929
    Rep Power
    481
    "You'll get a little farther if you recognize that string constants in c have double quotes"
    [code]Code tags[/code] are essential for python code and Makefiles!
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0
    Originally Posted by b49P23TIvg
    "You'll get a little farther if you recognize that string constants in c have double quotes"
    thanks, I changed that part already. At this point, I am guessing at the problems. Now re-reading my text book...again.

IMN logo majestic logo threadwatch logo seochat tools logo