I am trying to write a code in C++ to output the sum of the square of the odd numbers between 2 user input numbers (firstNum and secondNum). The code below is what I have, but it isnt working. Assignment due at midnight! number = firstNum; sum = 0; do { (number % 2 == 0); sum += (number * number); number++; number++; continue; } while (number <= secondNum); cout << "sum = " << sum << endl; cout << endl;
I am trying to write a code in C++ to output the sum of the square of the odd numbers between 2 user input numbers (firstNum and secondNum). The code below is what I have, but it isnt working. Assignment due at midnight!
number = firstNum;
sum = 0;
do
{
(number % 2 == 0);
sum += (number * number);
number++;
number++;
continue;
}
while (number <= secondNum);
cout << "sum = " << sum << endl;
cout << endl;
The program is written in c++
using namespace std;
#include <iostream>
int main() {
int number,firstNum, secondNum,sum;
cout<<"Enter first number"<<endl;
cin>>firstNum;
cout<<"Enter second number"<<endl;
cin>>secondNum;
number = firstNum;
sum = 0;
do
{
if(number % 2 != 0)
{
sum += (number * number);
number++;
}
else
{
number++;
continue;}
}while (number <= secondNum);
cout << "sum = " << sum << endl;
cout << endl;
return 0;
}
Step by step
Solved in 3 steps with 1 images