you should have used array. your counter value keeps on increasing, but every time the user inputs, it is stored in "score", thus overwriting the previous "score" value. and why did you start the counter from 2? :|
This is actually the whole program
#include <iostream>
using namespace std;
int main()
{
int max=0,max2=0,score,counter;
int c6=1,c5=0,c4=0,c3=0,c2,c1;
cout<<"Enter the twenty SAT scores :"<<endl;
cin>>score;
i've read your code and for the matter above, you'd have to learn array. assuming you take in 50 inputs, without array, you'd have to declare "int a1" all the way to "int a50". then cout a1 to a50. its not impossible, but not a good idea.
int c6=1,c5=0,c4=0,c3=0,c2,c1;
why does c6 initializes as 1, and the rest as 0? they all should be zero lol.
1 2 3 4 5 6
cout<<"Enter the twenty SAT scores :"<<endl;
cin>>score;
for(counter=2;counter<=20;counter++)
{
cin>>score;
if you use this way, notice that the first score does not enter the for loop, and therefore, the first score is not taken into consideration, regardless of its value.
and, why initialize "counter" from 2 to 20?
I've set them that way because the output would come out all weird and crazy, its very weird. I'm using Bloodshed dev C++ from that program in my post this is the output I get with c6=1, and counter being set to 2, I needed 20 inputs and setting counter=2 makes it 20.
This is the output. Now I'm having trouble getting the 2nd highest score, it keeps getting set to 0
Enter the twenty SAT scores :
750
750
750
650
650
650
550
550
550
450
450
450
350
350
350
250
250
250
250
250
750 = First highest score
0 = Second highest score
3 3 3 3 3 5
Press any key to continue . . .
well, you should try to get visual c++ express 2010. its better than dev c++ in my opinion. though its large lol and if you're a programmer, get visual studio 2010.
1 2 3 4 5
if(score>max)
{
max2=max;
max=score;
}
this condition never really works. first thing to consider was, what if there was two same scores, and both of them are the highest? logic-wise for me, the first highest score and the second are the same. and, ive tried checking around, but the second highest score is always not zero... i guess somethings wrong with your dev c++?
i have some free time in hand, so i pretty much coded your whole program. take a look at it. i tried it on visual c+ and its working fine.
Code::Blocks. It's not huge, it is simple. Once you get further into the programming language, then making the jump to VC could be a good idea, but I would say that for a beginner, it's a bit much (but not necessarily unreasonable).
Also:
@OP
Please use [code][/code] tags
@Ng Han Seng
Please don't make a habit of the following:
void main ()
main should always return an int
Doing the work for other people (especially without explanatory comments either in the code or elsewhere in the post). You're not really giving all that much help to the OP (remember, programming isn't just writing the code, it's problem solving as well).
i know that main should always be int, but i only practice this when the return value is not really important, or usually on small programs. thanks for the advice though.
well, standing at only 6 posts, including this, i'm practically new in this forum. thanks for the advice.