how can i find and print the winner in this case

Last edited on
a) You need to use arrays for this. I suppose, you just have learned it.
b) You program isn't comply to input format:
sent [...] in the following format: 1378 2496 3587 …

thanks for the reply
we didnt learn to use arrays yet ..so i think we must do it without using them
what do u mean by my program isnt comply to input format ??
here i should enter the grades so wherever grade i enter the program will work
so any help of solving it without using arrays ??
Pseudocode for you:

integer max_result = 0;
integer winner = 0;
for each contestant:
    Take contestant data
    calculate result
    if contestant result > max_result
        max_result = contestant result
        winner = contestant number
output winner and max_result
If i enter
1378 2496 3587 
just like in example i will get some ridiculos numbers.
so i work on it outside the while loop or inside it ??
how can i compute all candidte results (in my program s) after i exit the while loop ??
Output each candidate info while you processing it (inside loop)
Output winner info after loop.
enter the grade for beauty:4
enter the grade for elgance:5
enter the grade for education:6
1456
result of the candidate is48
enter the grade for beauty:5
enter the grade for elgance:7
enter the grade for education:4
2574
result of the candidate is51
....................
.............

here is what i get when i run my program
so my candidate info is mentioned
but how can i find which candidate has the best result
can u hellp me by writing the program
thank u for your time
1
2
3
4
5
6
7
8
9
int max_result = 0;
int winner = 0;
while//your while loop code here
    if(result > max_result) {
        max_result = result;//s variable in your code
        winner = curr_candidate;//current candidate number (c in your code)
    }
}//end while
std::cout << "candidate " << winner << " wins with score of " << max_result << std::endl; 

And in your assigment 1378 and so on should be input, not output.
Last edited on
uhm, maybe you can try something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
std::vector<int> candidates; //put the candidates results in this
int best;
int current;
best=candidates[0]-1000;
for(int i=1; i<candidates.size(); i++)
{
    current=candidates[i]-1000*(i+1);
    if (best<current)
    {
        best=current;
    }
}
printf("i",best);


Ps. you have to include:
1
2
#include <vector>
#include <stdio.h> 
thank you so much the program finally worked

i dont think 1378 2496 3587 should be input becasue they didnt give them all ...how can we know the result for the 4 and 5th candidate
did u get my point ??
i think they put them just as an example
what do u think ??
kajgies thank u so much
well i will try to run the program by the method u gave me
but i didnt learned <vector > and <studio.h >
so i cant use them in the assignment
thanks again
Miinipaa i just noticed something
when we write winner =c because if for example candidate 1 is the winner it will indicate that 2 is the winner and if candidate 5 is the winner it will indicate 6
so we must put winner = c-1
because in the wile loop we did an incrementation for c
Topic archived. No new replies allowed.