Hey everyone. Thanks for the help on the while loops. But now I'm confused on for loops. I'm writing the same program, just trying to replace the while loops with for loops. Here's what I got.... but when I compile, the same three errors keep coming up with "!=" twice and with "==". Can I not put operations like this in the for loop stuff?
Code:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int firstNum;
int secondNum;
int sum;
int squareSum;
int counter;
int i;
int square;
char c;
cout << "Enter two numbers." << endl;
cout << "First number must be less than or equal "
<< "to the second number you enter" << endl;
cout << "Enter numbers: ";
cin >> firstNum >> secondNum;
cout << endl;
counter = firstNum + 1;
if (firstNum <= secondNum)
{
cout << "Odd integers between " << firstNum << " and "
<< secondNum << " are: \n";
for (counter % 2 != 0; counter < secondNum; counter++)
{
cout << counter << " " << endl;
}
}
else if (firstNum > secondNum)
cout << "There are no odd integers between " << firstNum << " and "
<< secondNum <<endl;
sum = 0;
counter = firstNum + 1;
if (firstNum <= secondNum)
{
for (counter % 2 == 0; counter < secondNum; counter++)
{
sum += counter;
}
cout << "\nSum of even integers between " << firstNum << " and "
<< secondNum << " = " << sum << endl;
}
else if (firstNum > secondNum)
cout << "\nThere are no even integers between " << firstNum << " and "
<< secondNum << endl;
cout << left << setw(10) << "Number"
<< setfill(' ') << right << "Square of Number" << endl;
i = 1;
for (square = i * i; i <= 10; i++)
{
cout << right << setw(4) << i << setfill(' ') << right << setw(18) << square << endl;
}
cout << endl;
counter = firstNum + 1;
squareSum = 0;
if (firstNum <= secondNum)
{
for (counter % 2 != 0; counter < secondNum; counter++)
{
squareSum = squareSum + (counter * counter);
}
cout << "Sum of the squares of odd integers between "
<< firstNum << " and " << secondNum << " = ";
cout << squareSum << endl;
}
else if (firstNum > secondNum)
cout << "There are no odd integers between " << firstNum << " and "
<< secondNum <<endl;
cout << "Upper case letters are: ";
for (c = 'A'; c <= 'Z'; c++)
{
cout << c << " ";
}
cout << endl;
return 0;
}