1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Basic C++ calculations problem

  1. Feb 2, 2012 #1
    1. The problem statement, all variables and given/known data

    I am in a beginner c++ class and this is my second program. I am having trouble getting the calculations to output correctly. I'm not sure what I'm doing wrong here, maybe somebody can help.

    2. Relevant equations


    The program takes user input data for points in a class, like quiz points, test points, etc and calculates averages .


    The professor gave us a sample run of the program, which SHOULD output like this, but mine isn't:

    Enter total program points: 526
    Enter max number of points available: 580

    Enter the total quiz points earned: 73
    Enter the number of quizzes taken: 12
    Enter the sum of the two lowest quiz scores: 1

    Enter the total test points that have been earned(0 if no tests taken): 109
    Enter the max test points available: 300

    So that is the sample input data she gave us, and this is the sample output she gave us:
    *******
    Course Results

    Program average: 90.69
    Quiz Average: 72.00
    Test average: 45.25
    Course average: 63.43



    However, when I run my program with the sample input data, my output is all zeroes. Why would this happen?



    3. The attempt at a solution

    Here is my source code



    #include <iostream>
    #include <iomanip>

    using namespace std;

    int total_program_points,
    max_program_points,
    total_quiz_points,
    quizzes_taken,
    sum_lowest_quizzes,
    total_test_points,
    max_test_points;


    float program_average,
    quiz_average,
    test_average,
    course_average;


    int main()
    {










    cout<<"*******CSCI 240 Course Average Calculator*******"<<endl
    <<"This program will calculate the course average "<<endl
    <<"for a student in CSCI 240 after a few weeks of "<<endl
    <<" the semester have passed. "<<endl<<endl<<endl<<endl;



    cout<<"Enter the total program points that have been earned: ";
    cin>> total_program_points;

    cout<<endl
    <<"Enter the maximum number of program points available: ";
    cin>> max_program_points;

    cout<<endl<<endl
    <<"Enter the total quiz points that have been earned: ";
    cin>> total_quiz_points;

    cout<<endl
    <<"Enter the number of quizzes that have been taken: ";
    cin>> quizzes_taken;

    cout<<endl
    <<"Enter the sum of the two lowest quiz scores: ";
    cin>> sum_lowest_quizzes;

    cout<<endl<<endl
    <<"Enter the total test points that have been earned (0 if no test have been taken): ";
    cin>> total_test_points;

    cout<<endl
    <<"Enter the maximum test points available: ";
    cin>> max_test_points;



    //CALCULATIONS SECTION

    program_average = ((total_program_points/max_program_points)*100);

    quiz_average = ((total_quiz_points - sum_lowest_quizzes)/ (quizzes_taken*10)*100);

    test_average = ((total_test_points + total_quiz_points - sum_lowest_quizzes)/(max_test_points + (quizzes_taken -2)*10)*100);








    cout<<endl<<endl<<endl<<endl
    <<"Course results"<<endl<<endl<<endl
    <<"Program average: "<<program_average<<endl
    <<"Quiz average: "<<quiz_average<<endl
    <<"Test average: "<<test_average<<endl
    <<"Course average: "<<course_average<<endl;






    system ("pause");
    return 0;
    }
     
  2. jcsd
  3. Feb 2, 2012 #2
    First of all, make all of your variables doubles.
     
  4. Feb 2, 2012 #3
    Normally I would make them all float or double, but the professor specifically said that all of the user input data must be stored as integers.
     
  5. Feb 2, 2012 #4
    Then cast them as doubles when you divide.
     
  6. Feb 2, 2012 #5
    Ah, that was it. Thank you!
     
  7. Feb 2, 2012 #6
    Sure thing!
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Basic C++ calculations problem
  1. C++ Factorial Calculator (Replies: 30)

Loading...