How to write this code?

closed account (EApGNwbp)
thanks
Last edited on
something you can do:

1
2
3
4
if(passingscore > studentscore)
{
      //do the script for this
}


you can tweak it for your likes.
- i would do something like this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

double average=0;
double lowest=0;
double total;

void getScore(&double,&double);

void getScore(double av, double lo)
{

int k;
cout<<"how many quizes"<<endl;
cin>>k
double[k] scoreList;
for(int i=0;i<k;i++)
{

// get score for each student put it in the array

}


for
{
// put the values in total
}

// cast k, and use k and total to find the average
double smallest = scoreList[i];
for
{
// step through array, 
// use an if loop such as the user above mentioned
}

// etc, i apologize as i may have given you more hints than i should have, if not 
//worse...

}


}



closed account (EApGNwbp)
@thejman250 thanks um but I haven't learned arrays yet so I a bit lost. I am a beginner freshmen in college
@Dan1234
- Well, arrays would make this much easier and the concept is quite simple (in my opinion at least)

- you can read up on arrays on this very site, or use tutorials such as this: http://www.youtube.com/course?list=ECAE85DE8440AA6B83 , or maybe even read ahead in your book.

- In short, you can use whatever style works for you and you don't actually need your professor to teach you the language. In fact, reading ahead of time and/or watching tutorials will give you knowledge of the subject before the lecture, and will probably enable you to expand your knowledge upon the topic more than if you had simply waited for your professor to go over it.
You don't need to use arrays for this problem. You can perform the required calcs. as the user enters each value.

1) User enters numQuizzes.
2) Prompt for 1st score. Save this value as scoreTotal and as loScore, because so far it is both.
3) Each time user enters another score do 2 things:
a) add it to scoreTotal.
b) compare it to loScore. If it's less, then it's the new loScore.

4) After all scores are entered subtract loScore from scoreTotal, because the lowest score is thrown away.
5) Find average = scoreTotal/(numQuizzes-1);

The function signature you want is void getScore(double& av, double& lo) so that av and lo are passed by reference.

EDIT: That function may not meet all requirements. The instructions say to get the # of quizzes then call the function. You would need to pass numQuizzes to the function too. More like:
void getScore_data(int numQuizzes, double& av, double& lo)
Last edited on
Topic archived. No new replies allowed.