dummy value

rewrite readTestScore(), assuming that each student has one or more test score. A dummy test score of -99.00 is used to indicate the end of the test score for each student. Note that you only need to modify the function void readTestScore().

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
using namespace std;

void readTestScores(double & exam, double &tavge)
{
	double score, total = 0;
	cout << "ENTER EXAM SCORE\t:  ";
	cin >> exam;
	cout << "ENTER ALL TEST SCORES\t:  ";
	for (int count = 1; count <= 7;count=count+1)
	{
		cin >> score;
		total= total + score;
	}
	tavge = (total / 7);
does this not make sense, or does no one know?
Use a while loop with a sentinel rather than assuming the user is going to enter exactly 7 scores.
so do this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
using namespace std;

void readTestScores(double & exam, double &tavge)
{
	double score, total = 0;
	cout << "ENTER EXAM SCORE\t:  ";
	cin >> exam;
	cout << "ENTER ALL TEST SCORES\t:  ";
	while(-99.00)
	{
		cin >> score;
		total= total + score;
	}
	tavge = (total / -99.00);
@baketballcourt that is incorrect for several reasons.
thats what i would do what would be the correct way?
like this
while(score != -99.00)

you are also going to need a counter to keep track of how many scores are entered
tavge = (total / -99.00); tavge = (total / count);

and i would change this cin >> exam;
to this cin >> score;
Last edited on
Topic archived. No new replies allowed.