What's wrong with this program?

This is what I have for the following problem. It isn't right though and I don't know here to go from here.

"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."


#include <iostream>

int main()
{
// define number of scores
const int 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

const double 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
}
Hi,

I replied to your other post; also, might be a good idea to move this to the 'General C++ Programming' forum as you're not exactly talking about a job :)

Also, be sure to wrap your code in code tags (when you're writing your post, to the right of it should have some Format options which you can choose from). This makes it easier for all of us to help you (if applicable) and more importantly, to read it. :)

In any case, check your other post as I've replied to it and if you need a tutor, just let me know.

Joe
Last edited on
Topic archived. No new replies allowed.