Advertisement
Guest User

Ko thuya

a guest
Jan 22nd, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. //some lgoical errors, fixing it
  2. #include <iostream>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main (){
  7. int i = 0,v = 0 ,t = 0,a ; //declaration for loop counter, input value, total and average integers;
  8.  
  9. /*
  10. i =  counter
  11. v = value
  12. t = total
  13. a = average
  14.  
  15. */
  16. //cin>>v;
  17. //bool terminate (false);
  18. while (v =! 99)
  19. {
  20.     cin>> v; //user input
  21.  
  22.     if (v < 0 || v>10)
  23. {
  24.     cout<< "value must be in range of 0 to 10 \n";
  25. }
  26.     else
  27.     {
  28.         i++;
  29.         t += v;
  30.     }
  31. };
  32.  
  33. if ( i == 0 ) {
  34.  a = 0;
  35. }
  36. else {a = t/i;}
  37.  
  38. cout<< "average : "<< a;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement