I have a simple program that's bothering me because I can't do it. Can someone help me out?
"Write a program that allows you to input students' scores and weights. The program should then calculate a weighted average and score based on the data inputted by the user."
It would be useful to show us a sample of your code thus far. Also what exactly are you stuck on? You sound like a computer science 1 student, and this sounds like a homework assignment. While we at the forums love helping people with specific, we won't do your homework for you.
#include <iostream>
int main()
{
// define number of scores
constint NSCORES = 6 ;
// variables to hold the total weighted score and the total weight
double total_weighted_score = 0 ;
double total_weight = 0 ;
// accept 'NSCORES' score-weight pairs from the user,
// accumulate the total weighted score and the total weight as you go
int score ;
double weight ;
for( int i = 0 ; i < NSCORES ; ++i )
{
std::cout << "enter score and weight: " ;
std::cin >> score >> weight ;
// TO DO: validate that score and weight are within valid ranges
// if not, emit a message, and repeat the above two lines
constdouble weighted_score = score * weight ;
total_weighted_score += weighted_score ;
total_weight += weight ;
}
// TO DO: calculate weighted average (total_weighted_score divided by total_weight)
// and print it out
}
> The program you created for me isn't working. After I input the 5 scores it just ends and doesn't average them
In the two places marked with // TO DO , you are expected to add your own code to make the program complete.
Lines 18 - 21
1 2 3 4
std::cout << "enter score and weight: " ;
std::cin >> score >> weight ;
// TO DO: validate that score and weight are within valid ranges
// if not, emit a message, and repeat the above two lines
Lines 28, 29
1 2
// TO DO: calculate weighted average (total_weighted_score divided by total_weight)
// and print it out
"Validate" simply means to check if variables have proper values. I recommend reading up on the tutorials provided at this very site (conditions, specifically).
If you still need help, email me at: sparkprogrammer@gmail.com