Hello all,
Im new here and was hoping to get a bit of help with a program i am writing for class. The program has the user enter a start number then a ending number. Then displays only the Odd number. Ive been successful up to that point. The next part has been giving me a bit of a headache. Can you help?
After the odd numbers are displayed the program needs to Add those numbers together and display the sum. So if the user enters in 1 and 10 it will display 1,3,5,7,9 then 25 for the total sum. Any guidance would be much appreciated and I hope to hang around here and help anyone that might need it in the future.
Code:
#include <iostream.h>
#include <ctype.h>
#include <math.h>
void main()
{
char doAgn = 'Y';
int startNum= 0;
int endNum = 0;
int oddCount = 0;
int sum = 0;
int sumNum = 0;
while (toupper(doAgn) =='Y'){
//get inputs
cout<<"Please enter the beginning number:";
cin>>startNum;
cout<<"Please enter the ending number:";
cin>>endNum;
//display the odd numbers
for (int i = startNum; i < endNum; i++){
oddCount++;
if(oddCount % 2 !=0)
cout<<oddCount<<endl;
}//end For
//display the total sum for the odd numbers displayed
????????
//display the average for all the odd numbers displayed
//hopefully i will grasp this after understanding the above line of code.
//clear out odd count
oddCount = 0;
}//end while
}//end main