getScore();
calcAverage();
findLowest();
displayOutput(int getScore,float calcAverage, int everage);
}
return 0;
}
int getScore()
{
for (int i = 0; i < 5; i++)
{
cout << "Please enter a test score. ";
cin >> getScore;
}
while (getScore < 0 || getScore > 100)
{
cout << "Valid test scores range from 0 - 100.\n";
cout << "Please enter a test score. ";
cin >> getScore;
}
}
float calcAverage()
{
calcAverage = (test1 + test2 + test3 + test4 + test5);
cout <<"Average Score is "<< calcAverage <<endl;
cout << "The average of the four highest test scores is "<< average<<endl;
}
int findLowest()
{
double lowest = test1;
if (lowest > test2)
lowest = test2;
if (lowest > test3)
lowest = test3;
if (lowest > test4)
lowest = test4;
if (lowest > test5)
lowest = test5;
}
void displayOutput(int getScore, float calcAverage, float everage)
Okay, so I think your teacher probably confused you about functions because you should only call functions in main when you want to use them.
1 2 3 4
getScore();
calcAverage();
findLowest();
displayOutput(int getScore,float calcAverage, int everage);
That should all disappear. Also you need to be passing test1 through test5 as parameters to the other functions to calculate the average and find the lowest value. If you don't pass them as arguments it doesn't know what their values are and is just going to generate a compiler error. Try and fix it up as much as you can and post again if you need more help.
//Please check this program because i think with this one i am heading to the right direction
#include <iostream>
using namespace std;
int getScore (int test1,int test2,int test3,int test4,int test5)
{
getScore = getScore(test1,test2,test3,test4,test5)
//getScore++;
for ( i = 0; i < 5; i++)
{
cout << "Please enter a test score. ";
cin >> getScore; //test1 >> test2 >> test3 >> test4 >> test5;
}
while (getScore < 0 || getScore > 100)
cout << "Valid test scores range from 0 - 100.\n";
cout << "Please enter a test score. ";
cin >> getScore; //test1 >> test2 >> test3 >> test4 >> test5;
int findLowest(int test1, int test2, int test3, int test4,int test5)
{
findLowest(test1,test2,test3,test4,test5)
}
int main()
{
int test1, test2, test3, test4, test5;
float averageScore;
for (int i = 0; i < 5; i++)
{
test1 = getScore();
test2 = getScore();
test3 = getScore();
test4 = getScore();
test5 = getScore();
> it seems like i am having an immense trouble with my functions...it's frustrates me...where do i need to correct.
Don't panic; take in one small step at a time and surely you will eventually reach where you want to be.
For the present, forget all about this: 'Calculate the average of a group of test scores, where the lowest score in the group is dropped'. Let's start with something much simpler.
1 2 3 4 5 6 7 8 9 10 11 12
#include <iostream>
usingnamespace std ;
int main()
{
cout << "Please enter a number: " ;
int i ;
cin >> i ;
int j = i ;
cout << "you entered: " << j << '\n' ;
}
This program
a. accepts an integer entered by the user into the variable i
b. copies the value of i into another integer j
c. and finally prints out the value of j.
Now try to modify this by using a function int get_number() ; to accept an integer entered by the user.
This part of the code will be in the function get_number()
1 2 3
cout << "Please enter a number: " ;
int i ;
cin >> i ;
And this part will be in main()
1 2
int j = < the int returned by the function> ;
cout << "you entered: " << j << '\n' ;
The skeleton for this program would be:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
usingnamespace std ;
int get_number() ;
int main()
{
int j = get_number() ; // j gets the value returned by the function
cout << "you entered: " << j << '\n' ;
}
int get_number()
{
// TODO: prompt the user for input
// TODO: define an int variable that can hold the input
// TODO: read the value from cin into the variable
// TODO: return the value to the caller of the function (main)
// see: http://www.fredosaurus.com/notes-cpp/functions/return.html
}
Compile and run the program.
Once you have got this far, we can move on to the next (small) step.