I am new to c++ and i advice for this particular assignment. I new to programming.
The instruction is to use while loop for the two output process and for loop for the other 2 output.
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
int main()
{
system("color 4");
int firstNum, secondNum, num;
int sumE = 0, sumO = 0, sum_square = 0, firstNumA, secondNumB;
int a,z;
int counter = 10;
cout << "Enter first number: \a";
cin >> firstNum;
cout << "Enter second number: \a";
cin >> secondNum;
firstNumA = firstNum;
secondNumB = secondNum;
{
if (firstNum >= secondNum)
cout << "Wrong value \n" << endl;
else if (firstNum <= secondNum)
cout << "\n\n\nThe odd numbers are: " << endl;
while (firstNum <= secondNum)
{
if ((firstNum%2) != 0)
{
cout << firstNum;
sumO += firstNum;
}
firstNum++;
if (((firstNum % 2) != 0) && (firstNum != secondNum))
{
}
}
cout << "\n\n\nThe total odd number is: " << sumO << endl;
cout << "\n\n\nThe even numbers are: " << endl;
while (firstNumA != secondNumB)
{
if ((firstNumA % 2) == 0)
{
cout << firstNumA;
sumE += firstNumA;
}
firstNumA++;
if (((firstNumA%2) == 0) && (firstNumA != secondNumB))
{
}
}
cout << "\n\n\nSum of even numbers is: " << sumE << endl;
}
a = firstNum;
z = secondNum;
cout << firstNum;
sum_square += firstNum*firstNum;
while (a <= z)
{
cout <<"\n"<< firstNum <<"\t"<< firstNum * firstNum;
firstNum++;
}
cout << "\n\n\nThe sum square is: " << sum_square << "\n\n\n";
while (counter >=0)
{
cout << setw(counter+10) << counter << endl;
counter--;
}
system ("pause");
return 0;
}