there are some more modifications you'll have to make in order for this to work properly...
first, the divisions hits1/ab1, hits2/ab2, hits3/ab3 will not give you the result you expect. hits and ab variables are all ints, so these are integer divisions that will give an integer as a result. For example 5/2 will give you 2 instead of the desirable 2.5. To fix these you should type the divisions like
avg1=hits1/double(ab1);
or
avg1=double(hits1)/ab1;
or
avg1=double(hits1)/double(ab1);
This will force your compiler to make a double division and thus give you the result you want.
second, a typing error in the end of main, where you write
1 2
|
else if (avg3 > avg2 && avg3 > avg1)
cout << "The highest average belongs to " << name1 << " with " << avg1 << endl;
|
it should be
1 2
|
else if (avg3 > avg2 && avg3 > avg1)
cout << "The highest average belongs to " << name3 << " with " << avg3 << endl;
|
third, if avg1==avg2==avg3 (and in some other similar cases) then your program won't print anything. To avoid this you should use >= instead of > for your comparisons in the end of main.
and finally, add something like cin.get(); or system("pause"); before the return statement so that you can actually see the output of your program.