I have 5 scores, (and I do not know arrays well yet please no array answers) I just need help getting the formula correct and I think I can build the correct to find highest and then try to possibly rewrite the program using arrays but this is where i am. I have 5 ints score1, score2, score3, score4, score5. I am playing with the idea here is what i have at the moment. doesnt necessarily have to be a function just all the examples I see are for arrays and I dont get them yet(
However in your code it looks like you are trying to search for the minimum and the maximum of the five scores (but the code is not right for this task).
Example:
input -54 -76 -43 -87 -52
max == 0
min == -87
as you can see, the max should be -43 but it always comes out to zero... :(*/
int counter;
double num, max, min;
min = 0;
max = 0;
counter = 0;
while(counter < 5)
{
cin >> num;
if(num > max)
max = num;
if(num < min)
min = num;
counter ++;
}
cout << "Your max number is: " << max << endl
<< "Your min number is: " << min << endl;
system("pause");
return 0;
#include<iostream>
#include<vector>
#include<string>
#include<cctype>
#include <string.h>
#include <float.h>
usingnamespace std;
int main ()
{
int counter;
double num, max, min;
min = 0;
max = -DBL_MAX;
counter = 0;
while (counter < 5)
{
cin >> num;
if (num > max)
max = num;
if (num < min)
min = num;
counter++;
}
cout << "Your max number is: " << max << endl
<< "Your min number is: " << min << endl;
system ("pause");
return 0;
}
1 2 3 4 5 6 7
-54
-76
-43
-87
-52
Your max number is: -43
Your min number is: -87
I am trying to use findLowest and findHighest in a function to find highest and lowest scores but everything I try is failing?
I probably have alot of problems!
Ok, state your algorithm.
Assume you have N numbers.
+ What other variables do you need for the algorithm? What are their initial values prior to the algorithm (if necessary)
+ If you are writing a function, state the return value, extra parameters if needed
+ Does your function involve the uses of pointers & reference?
+ Try to imagine how many steps it would take to get the job done. Just show us all you've got. The more detailed the better.
+ Do you have to do all this in a single function? Or maybe two seperate functions.
+ If your algorithm fails, what the best action should you take to check the correctness of your algorithm?
Sorry if I sound indirect but you need to have a very good idea of what you have to do and understand your own plan throughly, or others' helps will be in vain.
P.S : It is not a very good idea to create a calAvgScore that does things it is not really supposed to do (findLowest, findHighest)
3. Use function calcAvgScore that has the contestant’s 5 scores as input parameters
a. returns the average score for that contestant.
b. Calls two functions, findLowest and findHighest which both accept the 5 scores as input parameters and return the lowest and highest scores, respectively.
4. Do not use global variables. All variables used in the functions must be passed as parameters or declared locally.
5. At the end of the program, display the winner and winning score (rounded to 2 decimal places).
Ok those are the exact destructions I have, to be honest I am completely overwhelmed with this one it has thrown in array along with multiple parameter functions both I have never done. I need score[5], counters but to be truthful I am lost I cannot make it run , well barely it isn't running correctly?
ok I have t evaluate each score and see which is highest but what I am to compare to is unknown to me? I have used a format I found in an example trying to piece the program together?
Hint : It is like :
Function <name> : param1, param2...
Step1 : Declare variable1, variable2
Step2 : variable1 = something
Step3 : Check param1 if it is divisable by 2. If the condition is true, proceed to Step4, otherwise jump to Step5