Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New to the CF scene
    Join Date
    May 2012
    Thanked 0 Times in 0 Posts

    Highschool junior taking programming classes, need help with C++ code

    Okay quick intro, I am a high school junior who is very interested in computer programming, and I am taking an intro to programming course at a nearby college. So far I am up to par with all the assignments and am enjoying the class, however the past 2 weeks I have been studying rigorously for the SAT’s and ACT’s that are coming up this week, so I haven’t been focusing that much in my programming class lately and I’m behind. I hate high school, and am ready to devote all my time to programming instead of doing these stupid tests, but sadly I will have to wait another 1.5 years! I have 2 questions, for the first question I just need someone to help me figure out the mistake I made in the code (I am new to programming so don’t be surprised if I may have made some silly mistakes). For the second question(the most important one), I need help with the code, but I don’t have the code because honestly, I’m spending all night juggling between studying the SAT’s and trying to code this problem( I have started the code, but having difficulty with arrays)! Please be aware that I am a beginner and I know these questions may be very easy to some people, but as a beginner they are pretty tough for me! (There have been a total of 10 lab assignments assigned to the class, and so far I have done all of them, except these 2, and I really need the last one, Thanks!)

    This is the first question:

    Create a program that calculates the average of three test scores:
    The program should contain 3 value-returning functions: main (), getTestScore (), and calcAverage(). The main () function should call the getTestScore () function to get and return each of 3 test scores. The test scores may contain a decimal place. (Hint: the main () function will need to call the getTestScore function three times.) The main() function then should call the calcAverage () function to calculate and return the average of the 3 test scores. When the calcAverage() function has completed its task, the main() function should display the average on the screen. Display the average with one decimal place.

    [MY CODE]: There is a mistake in here somewhere, but I cannot find it

    #include <iostream>
    #include <iomanip
    using namespace std;
    double getTestScore( double );
    double calcAverage( double, double, double );
    // there is no need for variable names in prototype declarations
    int main (int argc, char * const argv[]) {
    // Declare variables
    double Testscore1 = 0.0;
    double Testscore2 = 0.0;
    double Testscore3 = 0.0;
    double average = 0.0;
    cout << endl;
    // Get variables
    Testscore1 = getTestScore( Testscore1 );
    Testscore2 = getTestScore( Testscore2 );
    Testscore3 = getTestScore( Testscore3 );
    // set precision to 2 decimals
    cout << setprecision( 2 ) << setiosflags( ios::fixed | ios::showpoint );
    // Calculate average
    average = calcAverage( Testscore1, Testscore2, Testscore3 );
    cout << "\tThe average of the test scores is: " << average << "." << endl;
    cin>> average;
    return 0;
    } // end of main function
    // getTestScore Function
    double getTestScore (double score)
    cout << "\tEnter Test score: ";
    cin >> score;
    return score;
    } // end getTestScore Function
    // calcAverage Function
    double calcAverage (double Testscore1, double Testscore2 , double Testscore3) {
    double average = 0.0;
    average = (Testscore1 + Testscore2 + Testscore3) / 3; // divide the total by 3 because we only have 3 test scores
    return average;
    return 0;
    } // end calcAverage Function

    My Second question: The one I am having the most problems with

    In this exercise, you create a program that uses two parallel one-dimensional arrays. The program displays a shipping charge that is based on the number of items ordered by a customer. The shipping charge scale is shown in Figure 11-62. Store the maximum order amounts in a one-dimensional int array. Store the shipping charge amounts in a parallel one-dimensional int array. The program should allow the user to enter the number of items a customer ordered. It then should display the appropriate shipping charge. Use a sentinel value to stop the program. Save and then run the program. Test the program appropriately

    Figure: 11-62: (The bottom chart is figure 11-62)

    Minimum Order: 1, 11, 51, 101

    Maximum Order: 10, 50, 100, 99999

    Shipping Charge: 15, 10, 5, 0

    Once again I have no code for this one, because i am stressing out and still working on it and catching up! Your answer would be very much appreciated...THANKS!
    Last edited by Rangerwhat; 05-06-2012 at 04:27 AM.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts