Next time, at least post what exactly is going wrong. Are there errors? If so, which ones? Is it outputting the wrong value? Is it simply not accepting input?
Anyway, I'm assuming this is just an excerpt since you're missing declarations, includes and a namespace. So here goes:
a) Your loop is lacking encapsulation; only cin>>num is being executed 20 times, the rest only once after the while ends. I'm guessing the final value of sum is equal to the first number you type in?
b) Maybe just a typo but it should be "while(count<20)", not cout.
c) Adding additional values to a total is more efficient in this form: "sum+=num" ("add num to sum").
d) Since you're using a fixed number of iterations, you're better off with a for loop.
e) Not entirely sure, but I've always heard that "++i" is more efficient than "i++" since no copying is done.
Fix like this:
1 2 3 4 5
|
sum = 0;
for(int count = 0; count < 20; ++count) {
cin >> num;
sum+=num;
}
|