Okay, so. My program averages numbers entered by the user, it also counts how many numbers the user entered, that were valued over 100.
However, the counter does not work. It always counts one less than what was actually entered (over 100).
For example, say I tell the program I want to enter 5 numbers.
I enter the following 5 numbers; 1, 29, 91, 187 and 234.
The program would then tell me that the total average is 108.4 (which is correct), but it will also tell me I only entered 1 number over 100. When infact, I entered 2 (187 and 234).
I've been messing with this for a while and cannot seem to figure it out on my own, so I came here to see if anybody could point my in the write direction.
My code is listed below;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include <iostream.h>
#include <conio.h>
#include <dos.h>
main ()
{
int i;
float AV,Num, Sum,Average,Tally;
textcolor(LIGHTCYAN);
textbackground(BLACK);
clrscr();
Sum=0;
Tally=0;
cout<<"How many numbers are you planning on averaging? ";
cin>>AV;
for(i=1;i<=AV;i=i+1)
{
if(Num>=100)
{
Tally=Tally+1;
}
delay(250);
cout<<"Enter a number you want to average \n\n";
cin>>Num;
Sum=Sum+Num;
}
Average=Sum/AV;
delay(500);
clrscr();
cprintf("Your average is %.2f", Average);
cout<<"\n\n";
cout<<" You had "<<Tally<<" number(s) entered over 100.";
getch();
return 0;
}
|