c++ - How to differentiate scores between names using functions -



c++ - How to differentiate scores between names using functions -

i trying create talent show type voting programme using functions.

i have bulk of figured out. programme prompts come in name, followed 5 scores, if type "done" rather name, close. i'm using functions bulk of code practice them.

my big issue there infinite amount of names (as many user enters) , unaware on how add together 5 scores per name, not know how differentiate between them. 5 scores averaged , person highest average of (3 scores, dropping 2) winner.

side note: need drop highest , lowest score of each person, believe figure out illustration function of helpful new them.

i've researched lot not find examples similar plenty mine (having perchance infinite amount of contestants.)

here code far, function @ bottom me messing around functions hang of them , see if can sums of scores name.

#include <iostream> #include <string> using namespace std; void validcheck(); void calcavgscore(); void findhigh(); void findlow(); int main(){ int justice = 1; double score = 0; string name; while (name != "done" || name != "done"){ cout << "enter contestant name, if no more, type 'done': "; cin >> name; if (name == "done" || name == "done"){ break; } (judge = 1; justice < 6; judge++){ cout << "enter score " << justice << " "; validcheck(); } } system("pause"); homecoming 0; } void validcheck(){ double score; cin >> score; if (score < 1 || score > 10){ cout << "please come in score between 1 , 10: "; cin >> score; } } void calcavgcheck(){ double score = 0, value = 0; static int average; score += value }

declare string "winner", double "win_avg", double "avg" outside while loop.

have validcheck() homecoming double value given input (named score).

declare double array before loop (double[5] scores). store each value returned validcheck() array).

call std::sort(std::begin(scores), std::end(scores)) sort scores ascending. find average (ignoring max , min), , hold max average names of person max average.

#include <algorithm> // std::sort ... double validcheck(); ... int main(){ string name; string winner; double win_avg; double avg; while (name != "done" || name != "done"){ cout << "enter contestant name, if no more, type 'done': "; cin >> name; double scores[5]; if (name == "done" || name == "done"){ break; } (int justice = 0; justice < 5; ++judge){ cout << "enter score " << justice << " "; scores[judge] = validcheck(); } std::sort(std::begin(scores), std::end(scores)); for(int score = 1; score < 4; ++score) avg += scores[score]; avg /= 3; if(avg > win_avg) { winner = name; win_avg = avg; } avg = 0; } std::cout << "winner is: " << winner << "\n"; } double validcheck(){ double score; cin >> score; if (score < 1 || score > 10){ cout << "please come in score between 1 , 10: "; cin >> score; } homecoming score; }

if want find average in function , homecoming value can this

double calcavgcheck(const double& scores[5]) { double avg = 0.0; for(int score = 1; score < 4; ++score) avg += scores[score]; avg /= 3; homecoming avg; }

c++ function voting

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -