Why Is My C++ Program Outputting Zeroes Instead of Averages?

In summary, the program tries to calculate the average of a student's course results after a few weeks of class, but the sample data given doesn't seem to work. I'm not sure what I'm doing wrong, but somebody might be able to help me out.
  • #1
Joe_K
33
0

Homework Statement



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.

Homework 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?



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;
}
 
Physics news on Phys.org
  • #2
First of all, make all of your variables doubles.
 
  • #3
IntegrateMe said:
First of all, make all of your variables doubles.

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.
 
  • #4
Then cast them as doubles when you divide.
 
  • #5
IntegrateMe said:
Then cast them as doubles when you divide.

Ah, that was it. Thank you!
 
  • #6
Sure thing!
 

Related to Why Is My C++ Program Outputting Zeroes Instead of Averages?

1. What is the purpose of C++ calculations?

C++ calculations are used to solve mathematical problems and perform numerical operations in computer programs. It allows for efficient and accurate calculations in a variety of applications.

2. How do I write a basic C++ calculation?

To write a basic C++ calculation, you will need to use the appropriate mathematical operators such as addition, subtraction, multiplication, and division. You will also need to declare variables and assign values to them, and then use these variables in your calculation. Finally, you can use the output stream to display the result.

3. What are the common data types used in C++ calculations?

Some common data types used in C++ calculations include integer (int), floating point (float), and double. These data types allow for storing and manipulating different types of numerical values in a C++ program.

4. How do I handle errors in C++ calculations?

C++ calculations can produce errors if there are mistakes in the code or if there are invalid inputs. To handle these errors, you can use conditional statements and exception handling to catch and handle any errors that may occur during the execution of the program.

5. Can I perform more complex calculations in C++?

Yes, C++ has a wide range of mathematical functions and libraries that allow for more complex calculations, such as trigonometric functions, logarithms, and exponentials. These functions can be included in your program using the appropriate header files.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
13
Views
9K
  • Programming and Computer Science
Replies
1
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
  • Programming and Computer Science
Replies
1
Views
1K
Back
Top