Ok, i have been working on this program for a LONG time and i need some major help with the main.cpp file PLEASE.
I have to design a function that Designs and implements a function void getJudgeData() that asks the user for a judge's score, stores it in a reference parameter variable, and validates it. This function should be called by your function main() once for each of the 5 judges.

I dont get the reference parameter... Could anyone please please help me out i turned in the .cpp and .h files already and he said to not modify it anymore that it is good. To only work on the main.cpp and i need major help with the void getJudgeData part.


Main.cpp file

#include <iostream>
#include "Stat.h"

using namespace std;

void getJudgeData();
double calcScore();


int main()
{
    Stat s;

	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; 

// asking for the scores from each judge
//using the function getJudgeData
cout<<"Judge #1 ";
getJudgeData();
cout<<"Judge #2 ";
getJudgeData();
cout<<"Judge #3 ";
getJudgeData();
cout<<"Judge #4 ";
getJudgeData();
cout<<"Judge #5 ";
getJudgeData();


system("pause");
	return 0;
}

void getJudgeData()
{
     Stat s;
    s.getNum("Please enter your score ");
  
 
}

double calcScore()
{
       Stat s;
       s.getAverage= (s.getSum - s.getMin - s.getMax)/3;
}

the idol.cpp file

#include <iostream> // for cin, cout
#include "Stat.h"

using namespace std;

Stat::Stat(  ){
    reset( );
}

void Stat::setNum ( int newNum ){
    thenum = newNum;
//  update data members
    if( count==0 ) // first integer entered
        min = max = thenum;
    count++;
    sum  = sum+thenum;
    prod = prod*thenum;
    if( thenum<min )
        min = thenum;
    if( thenum>max )
        max = thenum;
    if( thenum%2==0 )
        evens++;
    else
        odds++;
}

void Stat::getNum ( string prompt ){
    int someInt;
    cout << prompt;
    cin  >> someInt;
    setNum( someInt );
}

void Stat::reset (  ){
    count = 0;
    sum   = 0;
    prod  = 1;
    evens = 0;
    odds  = 0;
}

int Stat::getNum (  ){
    return thenum;
}

unsigned Stat::getCount (  ){
    return count;
}

int Stat::getSum (  ){
    return sum;
}

long Stat::getProd (  ){
    return prod;
}

int Stat::getMin (  ){
    return min;
}

int Stat::getMax (  ){
    return max;
}

float Stat::getAverage (  ){
    return (1.0 * sum) / count;
}

unsigned Stat::getEvens (  ){
    return evens;
}

unsigned Stat::getOdds (  ){
    return odds;
}

and the header file

// FILENAME:        Stat.h
//
// CLASS PROVIDED:  Stat

#ifndef STAT_H
#define STAT_H

#include <string>

using namespace std;

class Stat {

  // ATTRIBUTES /////////////////////////////////////////////////////////

  private:
     int      thenum; // last integer entered
     unsigned count;  // number of integers entered so far
     int      sum;    // sum of all integers entered so far
     long     prod;   // product of all integers entered so far
     int      min;    // minimum of all integers entered so far
     int      max;    // maximum of all integers entered so far
     unsigned evens;  // count of evens of all integers entered so far
     unsigned odds;   // count of odds  of all integers entered so far

  // OPERATIONS /////////////////////////////////////////////////////////

  public:
     Stat( );
  // - default constructor
     void setNum ( int newNum );
  // - sets the last integer entered to newNum
     void getNum ( string prompt );
  // - displays prompt and reads in another integer
     void reset (  );
  // - resets all statistical values
     int getNum (  );
  // - returns the last integer entered
     unsigned getCount (  );
  // - returns the number of integers entered so far
     int getSum (  );
  // - returns the sum of all integers entered so far
     long getProd (  );
  // - returns the product of all integers entered so far
     int getMin (  );
  // - returns the minimum of all integers entered so far
     int getMax (  );
  // - returns the maximum of all integers entered so far
     float getAverage (  );
  // - returns the average of all integers entered so far
     unsigned getEvens (  );
  // - returns the number of even integers entered so far
     unsigned getOdds (  );
  // - returns the number of odd integers entered so far

};

#endif

Dani AI

Generated

— the core problems are: getJudgeData creates its own Stat (so scores never accumulate in main) and calcScore tries to assign to the member accessor instead of computing with the Stat already filled in. was right to suggest using a score variable passed by reference and declaring the Stat in main; below is a compact, safe way to do that and to compute the average after dropping highest and lowest.

// add at top of main.cpp
#include <limits>

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

// read five validated scores into the Stat in main
int main() {
    Stat s;
    int score;
    for (int i = 1; i <= 5; ++i) {
        cout << "Judge #" << i << " ";
        getJudgeData(score);   // fills score by reference
        s.setNum(score);       // commit the validated score to Stat
    }
    cout << "Final score (drop high/low): " << calcScore(s) << endl;
    return 0;
}

void getJudgeData(int &score) {
    while (true) {
        cout << "Please enter score (0-10): ";
        if (!(cin >> score)) {
            cin.clear();
            cin.ignore(numeric_limits<streamsize>::max(), '\n');
            cout << "Invalid input. Enter an integer." << endl;
            continue;
        }
        if (score < 0 || score > 10) {
            cout << "Score must be 0..10. Try again." << endl;
            continue;
        }
        break;
    }
}

double calcScore(const Stat &s) {
    if (s.getCount() < 3) return 0.0; // safety
    double middleSum = s.getSum() - s.getMin() - s.getMax();
    return middleSum / 3.0;
}

Notes: adjust the 0..10 range if the assignment expects a different one. Do not create a local Stat inside getJudgeData — that prevents main() from seeing values. Use cin.clear()/cin.ignore() to handle non-numeric input. Avoid assigning to getAverage (it's a function); compute with getSum(), getMin(), and getMax() and use 3.0 to force floating-point division.

Good day. A few points for you:
1.You need to declare a score variable and reference that in your function.
2.You need to be declaring a Stat in your main.
3.You will need a loop that will repeat your main untill a 'y' is entered in the final user input(cin).

Be a part of the DaniWeb community

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