C++ code using while loop

Hi everybody, I need a help to code a C++ program "should include while loop" that prompt the user to enter a range between any two integers, and output the counter, sum, and average..

I've started coding but i think i miss alot of things,I a beginner, I've started using C++ before 2 months, I need your help alot
Thank you all..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
using namespace std;
int main()
{ 
  int average, counter;
  const int i=1, n=1, sum=0;
  double average;
  
  cout <<"Please enter the range"<<endl;
  cin>> n >> i;

  while (n>i);
  {
   sum = sum + n
  counter++
  }

  return 0;
}
Last edited on
what else do you need in your code?
Line 5,7 - You declaring two variables with the same name. I'm guessing you only meant to have one "average" variable.

Line 10 - n and i have been declared to be constants on line 6, so you won't be able to change them with user input. Similarly on line 14, you're trying to change the value of a constant variable sum.


Line 12 - remove the semicolon after the while condition
Line 14,15 - missing semicolons at the end of these statements

Line 12 - How do you know that n will be greater than i? Even if it is, nothing in the while loop right now changes either of those values so that the while loop will eventually terminate.
Thanks wildblue for your help.. I understand my errors, but I don't know how to solve the whole code until now,, i should output the counter, sum, and average..
Topic archived. No new replies allowed.