Help with loop for Averaging

I'm having trouble figuring out how to average the numbers 1-N where N is the user's input. All of which to construct the code from what we have learned from chapter 5 and 6.
The question is: For a number N input by the user,
Print the average of all numbers from 1 to N,
Print the average of all even numbers from 1 to N, and
Print the average of all odd numbers from 1 to N.
Print the highest average value
Print the least average value

here is what I have so far, anything can help me. Thank you in advance!

#include <iostream>
#include <iomanip>
using namespace std;

int even =0;
int odd =0;
int number =0;

int main()
{
int i=0; //holds index for the loop
int input=0;
int eventotal=0;
int oddtotal=0;

do
{
cout<<"Enter a number: "
cin>>number;

if((number%2 ==0) && (number>0))
(
even++;
eventotal= eventotal+number;
}
else if(number>0)
{
odd++;
oddtotal= oddtotal+number;
}
while(number !=0)
int oddavg= 0; //stores average of odd numbers
if(oddtotal !=0)
oddavg= oddtotal/odd;

int evenavg= 0; //stores average of even numbers
if(eventotal !=0)
evenavg= evenavg/even;

cout<<"Average of odd numbers: " <<oddavg<<endl;
cout<<"Average of even numbers: "<<evenavg<<endl;
}

return 0;
}

Above is the averages of the odd and even numbers between numbers 1 and whatever number the user decides to enter.
i honestly do not know why i am stuck on this, but it is really frustrating! once again, if the code is completely wrong, i am a beginner so sorry if there is any confusion.
if the user must input only 1 time then think where should that 'cin' be placed,
in this code, you stop taking input , only when input = 0
Last edited on
So put it before the "Do" right? And then what do I do in order to calculate the average of all the numbers between 1 and whatever they input?
1 .yes
2. start a for(or while) loop from 1 to (user input); and check each value you get while going through this loop.
Would that be:

If(i !=0; i <= number; i++)
{
sum= sum+ i;
average= sum/i;
cout<<"The Average of all numbers between 1 and the number you";
cour<<" Entered: "<<average<<endl;
}

Or does that not make any sense at all.
Well take out the "!" In "i !=0" And just put "i=0;"
How would you find the average of all even and odd numbers?
Topic archived. No new replies allowed.