without messing with the class, cause i cant modify it , i was wondering if there is a way to return thefunction calcscore as a float. I cant modify the class, where i call the function
"This contestants average score was..." it always just returns a .000 is there a way to pass it as a float without messin with the class?
//Jeremy Rice
// CSCI 111
// FALL 2007
#include <iomanip> // for setw(), setprecision()
#include "Stat.h"
#include <iostream>
using namespace std;
//Function Prototypes
void getJudgeData(int &);
double calcScore(Stat s);
const unsigned W=25; // argument for setw()
const unsigned P= 3; // argument for setprecision()
void showStat( Stat ); // displays statistics from Stat object
int main()
{
//Initilizing variables and class
Stat s;
int score1 = 0, score2 = 0, score3=0, score4=0, score5=0;
int x = 1;
double total = 0;
double winner = 0;
double contest;
char z;
cout << "This program assignment number #4"<<endl;
cout<< "THE NEXT AMERICAN IDOL"<<endl;
cout<< "By Jeremy Rice of CSCI 111"<<endl;
cout<<endl;
cout<< "Please enter your scores below!"<<endl;
//Ask each of the Judges for a score from 1-10
//anything less than 0 and greater than 10 will not be accepted
do
{
s.reset();
cout<< "Enter contestant #"<<x<< " scores!"<<endl;
cout<<setw(W)<<"\tJudge #1 what is your score [0...10] : ";
getJudgeData(score1); //calling function for score1
s.setNum(score1);
cout<<setw(W)<<"\tJudge #2 what is your score [0...10] : ";
getJudgeData(score2); //score2
s.setNum(score2);
cout<<setw(W)<<"\tJudge #3 what is your score [0...10] : ";
getJudgeData(score3); //score3
s.setNum(score3);
cout<<setw(W)<<"\tJudge #4 what is your score [0...10] : ";
getJudgeData(score4); //score4
s.setNum(score4);
cout<<setw(W)<<"\tJudge #5 what is your score [0...10] : ";
getJudgeData(score5); //score5
s.setNum(score5); //storying it into class
cout<<"Talent score for contestant #"<<x<<" is: ";
cout<<setprecision(P)<< setw(W+P+1) <<fixed <<calcScore(s)<<endl;
// Initilizing total to the Average
// This is to determine the winner
// If total is greater than winner set the winner as total
// and the winning contestant to variable x
total = calcScore(s);
if (total > winner )
{
winner = total;
contest = x;
}
// increase variable for the next contestant
x++;
cout<<"Is there another contestant? (Y/N): ";
cin>>z;
//Asking if there is another contestant
}while ((z == 'y')||(z == 'Y'));
cout<< "The Next American Idol is Contestant "<<contest<<"!!!"<<endl;
cout<< "With a winning score of "<<winner<<"!!!"<<endl;
system("pause");
return 0;
}
// If judge score is less then 0 and grester than 10 reask for score
//return number to score1-5
void getJudgeData(int &getNum)
{
Stat s;
cin>> getNum;
while( (getNum < 0 ) || (getNum > 10))
{
cout<<"That is not a digit between 0 and 10"<<endl;
cout<< "Please re-enter your score: ";
cin>>getNum;
}
return;
}
//calculating average
//average is the sum subtracted by the min and max of the stat class
double calcScore(Stat s)
{
float avg = 0;
avg = (s.getSum() - s.getMax() - s.getMin()) / 3;
return avg;
}