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(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;
}