Ok, i made a psot earlier but my code is alot different and different question so i didnt know where to put it.

My question is thiss... in my calcScore function. This is my requirement:
Design and implement a function double calcScore() that calculates and returns the average of the three scores that remain after dropping the highest and lowest scores a performer received. This function should be called once for each contestant by your function main(), and it should be passed the Stat object that contains the 5 scores from the judges.

I am having trouble of passing the values of score 1-5 into the calcScore function. If i didnt have to use the function it wouldnt be a problem. But I do, and i dont know how to do it.

#include "Stat.h"
#include <iostream>
using namespace std;

void getJudgeData(int &);
double calcScore();

int main()
{
    Stat s;
    int score1 = 0, score2 = 0, score3=0, score4=0, score5=0;
    

	cout << "This program assignment number 4 was created by Jeremy Rice" << endl;
	cout<<  "The Next American Idol!!!"<<endl;
    cout<< "Please enter your scores below!"<<endl; 

cout<< "Enter contestant #1's scores!"<<endl;
cout<<"Judge #1 what is your score"<<endl;
getJudgeData(score1);
s.setNum(score1);
cout<<"Judge #2 what is your score"<<endl;
getJudgeData(score2);
s.setNum(score2);
cout<<"Judge #3 what is your score"<<endl;
getJudgeData(score3);
s.setNum(score3);
cout<<"Judge #4 what is your score"<<endl;
getJudgeData(score4);
s.setNum(score4);
cout<<"Judge #5 what is your score"<<endl;
getJudgeData(score5);
s.setNum(score5);


cout<<"Talent score for contestant #1 is: "<<calcScore()<<endl;


system("pause");
	return 0;
}

void getJudgeData(int &getNum)
{
     Stat s;
    cin>> getNum;
     return;
}

double calcScore()
{
        
       Stat s;
      cout<<(s.getSum()- s.getMin()- s.getMax()) / 3 <<endl;
      
}

Recommended Answers

All 5 Replies

Er, sure I have time for one more...

Don't use system("pause"); . Tell your professor it is evil and non-portable and he shouldn't be teaching it. If he gives you a hard time tell him people who know better than he know better. (Yes, I know that sounds non-sequitur, but he should know better either way.)

If you must, use while (cin.get() != '\n'); instead.

Now for your problem.
Make your calcScore() function take an argument: double calcScore( Stat s ); Then you can pass the Stat object you created in main() to the function to calculate the score instead of creating a new, useless Stat object in the function itself. Also, the function should return a value, not print anything.

Hope this helps.

Wow awesome i finally got it, thanks for the help !!! like majorly couldnt of done without help.
I do have one last question. What do I do to start a loop for it all? from the part "is there another contestant?" if i press Y how would i loop that back to the begining?

#include "Stat.h"
#include <iostream>
using namespace std;

void getJudgeData(int &);
double calcScore(Stat s);

int main()
{
    Stat s;
    
    int score1 = 0, score2 = 0, score3=0, score4=0, score5=0;
    int x = 1;
    int winner;


	cout << "This program assignment number 4 was created by Jeremy Rice" << endl;
	cout<<  "The Next American Idol!!!"<<endl;
    cout<< "Please enter your scores below!"<<endl;
     

  cout<< "Enter contestant #"<<x<< " scores!"<<endl;
  cout<<"Judge #1 what is your score: ";
               getJudgeData(score1);
               s.setNum(score1);
  cout<<"Judge #2 what is your score: ";
               getJudgeData(score2);
               s.setNum(score2);
  cout<<"Judge #3 what is your score: ";
               getJudgeData(score3);
               s.setNum(score3);
  cout<<"Judge #4 what is your score: ";
               getJudgeData(score4);
               s.setNum(score4);
  cout<<"Judge #5 what is your score: ";
               getJudgeData(score5);
               s.setNum(score5);
  
  cout<<"Talent score for contestant #"<<x<<" is: ";
                calcScore(s);
                x++;
  cout<<"Is there another contestant? (Y/N)"<<endl;

  
    system("pause");
	return 0;
}



void getJudgeData(int &getNum)
{
     Stat s;
    cin>> getNum;
     return;
}

double calcScore(Stat s)
{
        
cout<<(s.getSum()- s.getMin()- s.getMax()) / 3 <<endl;
      
}

to go back to the beginning, one way is to use a label, like so:

int main()
{
    Stat s;
    
    int score1 = 0, score2 = 0, score3=0, score4=0, score5=0;
    int x = 1;
    int winner;


	cout << "This program assignment number 4 was created by Jeremy Rice" << endl;
	cout<<  "The Next American Idol!!!"<<endl;

enterScores:        //<--------the new stuff
system("cls");      //<------ jaja i know :( system

    cout<< "Please enter your scores below!"<<endl;
     

  cout<< "Enter contestant #"<<x<< " scores!"<<endl;
  cout<<"Judge #1 what is your score: ";
               getJudgeData(score1);
               s.setNum(score1);
  cout<<"Judge #2 what is your score: ";
               getJudgeData(score2);
               s.setNum(score2);
  cout<<"Judge #3 what is your score: ";
               getJudgeData(score3);
               s.setNum(score3);
  cout<<"Judge #4 what is your score: ";
               getJudgeData(score4);
               s.setNum(score4);
  cout<<"Judge #5 what is your score: ";
               getJudgeData(score5);
               s.setNum(score5);
  
  cout<<"Talent score for contestant #"<<x<<" is: ";
                calcScore(s);
                x++;
  cout<<"Is there another contestant? (Y/N)"<<endl;

//more new stuff below

if (cin.get() == 'y' || cin.get() == 'Y'){
         goto enterScores;
         }
  
    system("pause");
	return 0;
}

i havent tried this code but as far as i can see there should be no errors.. if im wrong please someone correct me

o well give it a go hope it helps

I'm not a big fan of 'goto'...

You could try something like:

int main(void)
{
    char Choice = 'Y';
 
    while (Choice == 'y' || Choice == 'Y')
    {
         // do your stuff
        cout << "More?" << endl;
        Choice = cin.get();
    }
}

It will continue your program until something else then 'Y' or 'y' is entered.

oh ja.... seen that used somewhere before. bit more efficient i'd guess. up to you though jrice

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.