Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,120 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,770 people online right now. Registration is fast and FREE... Join Now!




Finding the highest score of five test scores

 
Reply to this topicStart new topic

Finding the highest score of five test scores

nydia22
15 Apr, 2007 - 07:16 PM
Post #1

New D.I.C Head
*

Joined: 15 Apr, 2007
Posts: 17


My Contributions
I am writing the following program that calculates the average of a group of test scores where the lowest score in the group is dropped. It has the following functions:
  1. void getScore()-should ask the user for a test score, store it in a reference parameter variable, and validate it. This function should be called by main once for each of the five scores to be entered.
  2. void calcAverage() should calculate and display the average of the four highest scores. This function should be called just once by main and should be passed the five scores.
  3. int findLowest(): should find and return the lowest of the five scores passed to it. It should be called by the calcAverage, who uses the function to determine which of the five scores to drop.

So far, here is my version of the program:

CODE
#include <iostream>
#include <conio>
using namespace std;

//Function prototype
void getscore(int, int, int, int, int);


int main()
{
        int score1, score2, score3, score4, score5;

        cout << "Enter your five test scores: ";
        cin  >> score1  >> score2 >> score3  >> score4  >> score5;
        getscore (score1, score2, score3, score4, score5) <<endl;
        getch();
        return 0;
}

void getscore(int score1, int score2, int score3, int score4, int score5)
{
        cout << "Your five test scores are:\n";
        cout << score1 <<endl;
        cout << score2 <<endl;
        cout << score3 <<endl;
        cout << score4 <<endl;
        cout << score5 <<endl;
}


But, as far as the void calcAverage() and the int findLowest() functions, I am totally confused. I have read my textbook. My instructor tells me that I can use an if-else statement for this program to find the lowest score; she doesn't want us using MAX or MIN or anything like that; we haven't gotten that far.

I need major help. crazy.gif Any input is appreciated.
User is offlineProfile CardPM
+Quote Post

AmitTheInfinity
RE: Finding The Highest Score Of Five Test Scores
16 Apr, 2007 - 12:56 AM
Post #2

C Surfing ∞
Group Icon

Joined: 25 Jan, 2007
Posts: 1,025



Thanked: 35 times
Dream Kudos: 125
My Contributions
First thing is about your getscore function. It will not store those input scores into the variables of main by the way which you are calling it.
You need to either pass the addresses of those variables or make those variables global and don't send them as parameter.

now about finding the lowest then you can use if else or ternary operator for if else.

CODE

if(a>=b&&a>=c&&a>=d&&a>=e) printf(a);
else if(b>=a&&b>=c&&b>=d&&b>=e) printf(b);
else if(c>=a&&c>=b&&c>=d&&c>=e) printf(c);
else if(d>=a&&d>=b&&d>=c&&d>=e) printf(d);
else if(e>=a&&e>=b&&e>=c&&e>=d) printf(e);


it's a logic that you can modify for your use.
User is online!Profile CardPM
+Quote Post

nydia22
RE: Finding The Highest Score Of Five Test Scores
16 Apr, 2007 - 04:41 AM
Post #3

New D.I.C Head
*

Joined: 15 Apr, 2007
Posts: 17


My Contributions
So, how exactly do I pass the addresses of the getscore() variables? I assumed that I was doing it the correct way because I am supposed to ask the user for five scores in the getscore function, and that was it. Then I was supposed to go from there, with the calcAverage and the findLowest functions.

This post has been edited by nydia22: 16 Apr, 2007 - 04:42 AM
User is offlineProfile CardPM
+Quote Post

dizzywiggle
RE: Finding The Highest Score Of Five Test Scores
16 Apr, 2007 - 04:54 AM
Post #4

New D.I.C Head
*

Joined: 13 Apr, 2007
Posts: 9


My Contributions
Currently, getscore is having its parameters passed in by value. This essentially creates copies of the values. So when getscore gets values from the user, the values are placed in the copies, and disappear into the ether whenever getscore returns. As you stated, you want to pass the values into getscore by reference. This doesn't create copies. When you pass by reference, the variables used in the function signature actually "refer" to the variables you passed in. The way to do this is to declare getscore like this...

void getscore(int &a, int &b, int &c, int &d, int &e);

Using the & character in the variable declaration means that it's a reference variable.

Now when you assign to, say, "a" in the getscore function, the variable you passed in for "a" will actually get the value you assign. Does that make sense?

-Shane


QUOTE(nydia22 @ 16 Apr, 2007 - 05:41 AM) *

So, how exactly do I pass the addresses of the getscore() variables? I assumed that I was doing it the correct way because I am supposed to ask the user for five scores in the getscore function, and that was it. Then I was supposed to go from there, with the calcAverage and the findLowest functions.


User is offlineProfile CardPM
+Quote Post

nydia22
RE: Finding The Highest Score Of Five Test Scores
16 Apr, 2007 - 12:25 PM
Post #5

New D.I.C Head
*

Joined: 15 Apr, 2007
Posts: 17


My Contributions
Ummm I don't mean to sound like a total airhead, but it really doesn't make any sense to me at all. sad.gif Like I said, I am really new at this, so it may take me a minute to catch on to it.

This post has been edited by nydia22: 16 Apr, 2007 - 12:32 PM
User is offlineProfile CardPM
+Quote Post

k0b13r
RE: Finding The Highest Score Of Five Test Scores
16 Apr, 2007 - 02:04 PM
Post #6

D.I.C Head
Group Icon

Joined: 18 Jul, 2006
Posts: 196



Thanked: 1 times
Dream Kudos: 250
My Contributions
Maybe try using some sorting algorithm? In example, bubble sort.
It's simple and you will get your highest number easy.
Here is little implementation in C++: http://www.dreamincode.net/code/snippet951.htm
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 10:01PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month