## Exo1337

Write a program that uses while loops and performs the following

Prompts the user to input 2 integers firstNum and secondNum // Easy

Output all odd numbers between firstNum and secondNum // No idea how to start that.

Outputs the sum of all even numbers between firstNum and secondNum

Output the numbers and their squares between 1 and 10

Output the sum of the square of the Odd Numbers between firstNum and secondNum

Output ALL Uppercase letters***.

I have no idea how to even start this program other then the basic input statement, a point in the right direction would be appreciated ^^;

-Exo

## lAmoebal 1

Prompts the user to input 2 integers firstNum and secondNum // Easy

Output all odd numbers between firstNum and secondNum // No idea how to start that.

Outputs the sum of all even numbers between firstNum and secondNum

Output the numbers and their squares between 1 and 10

Output the sum of the square of the Odd Numbers between firstNum and secondNum

These would all be easier to do with a for loop really, but if you're required to create a while loop, use this pseudocode to help..

while i < second num
{
//code
i++
}

In order to find if they're even numbers, use i%2 and if it equals 0, then it's even. Otherwise it's odd. A simple if/else can help there.

sum += sum + i;

Make sure you start sum at 0 before the loop.

I'm not sure I understand what the 'Output ALL Uppercase numbers' is?

## vmanes 1,165

<snip>

sum += sum + i;

Make sure you start sum at 0 before the loop.

You really meant either:

``````sum += i;
//or
sum = sum + i;``````

right?

The uppercase letters problem - use a loop with a character as the loop variable, starting it at 'A'. Increment it till it's 'Z'

## Exo1337

``````#include <iostream>

using namespace std;

int main()
{
cout << "Please input 2 integers: ";
cin >> firstNum >> secondNum;
cout << endl;

while (firstNum >= secondNum)``````

Im honestly stuck and cannot find any examples of this in my book could i get a little more help ?

## lAmoebal 1

Which do you need more help with?

And yeah Vmanes, I definitely meant that =P

## Exo1337

Im not asking anyone to hold my hand thru this problem im just at a road block i definetly learn better by seeing actual codes and the fact my book shows no similar exaples sucks so If you can tell me another step or 2 based on my code i posted i might be able to head in the right direction

## Ab000dy_85 -3

``````#include <iostream>

using namespace std;

int main()
{
cout << "Please input 2 integers: ";
cin >> firstNum >> secondNum;
cout << endl;

////while (firstNum >= secondNum) <<-- Dont use it like that``````

this way would be better,

int i = firstNum;
int sum = 0, sum2 = 0;
While ( i < secondNum )
{
if ((i %2) == 0)// for odd if (i%2 == 1) is odd
sum +=i; //<-- sum all the even number, if you want odd
else// the if its not even then it is odd
{
cout<< i << " ";
sum2+= i*i;// for the square
}
i++;
}

## Exo1337

What would i initialize second num as ?

## Ab000dy_85 -3

the firstNum and the second are constat as soon as the user input them.
so no worry about initlizing them,
but you initialize the i just to make sure you use the i to go throw all the number from the firstNum and thal last.
then you dont have to change them.
so you can use them later if you want.

## Exo1337

I feel really stupid perhaps im just not understanding what is being put here

## Exo1337

``````#include <iostream>

using namespace std;

int main()
{
int i = firstNum;
int sum = 0, sum2 = 0;

cout << "Please Enter 2 Integers: ";
cin >> firstNum >> secondNum;
cout << endl;

while (i < secondNum)
{
if ((i %2) == 0)
if (i%2 == 1)
sum +=i;
{
cout<< i << " ";
sum2+= i*i;// for the square
}
i++;
}
return 0;
}``````

very skeletal but working, on it ^^; another tip ?

## Ab000dy_85 -3

did you understand the code I have written.
its just need time to be familiar with everyththing.
and I rememebr my self being t=in the same spot. I hade 2 corces in C++. so these stuff look easy. but now am trying to get familiar to the stuff we are studying.

## Ab000dy_85 -3

``````#include <iostream>

using namespace std;

int main()
{
int i;
int sum = 0, sum2 = 0;

cout << "Please Enter 2 Integers: ";
cin >> firstNum >> secondNum;
cout << endl;

i = firstNum; // <== Should be here so the input value goes here.

while (i < secondNum)
{
if ((i %2) == 0)
if (i%2 == 1)
sum +=i;
{
cout<< i << " ";
sum2+= i*i;// for the square
}
i++;
}
return 0;
}
``````

## Exo1337

Im getting alot more errors with your coding advice then i was originally perhaps im misinterpreting

## Exo1337

``````#include <iostream>

using namespace std;

int main()
{
int i;
int sum = 0, sum2 = 0;

i = firstNum;

while (i < secondNum)
{
cout << "Please enter 2 integers, the first must be smaller then the second: ";
cin >> firstNum >> secondNum;
cout << endl;

if ((i %2) == 0)
if (i%2 == 1)
sum +=i;
{
cout<< i << " ";
sum2+= i*i;
}
i++;
}
return 0;
}``````

Write a program that uses while loops and performs the following

Prompts the user to input 2 integers firstNum and secondNum // Easy

Output all odd numbers between firstNum and secondNum // No idea how to start that.

Outputs the sum of all even numbers between firstNum and secondNum

Output the numbers and their squares between 1 and 10

Output the sum of the square of the Odd Numbers between firstNum and secondNum

Output ALL Uppercase letters***.

*Bump*

## lAmoebal 1

``````#include <iostream>

using namespace std;

int main()
{
int i;
int firstNum, secondNum;
int evensum = 0;
int oddsum = 0;

cout << "Please enter 2 integers: ";
cin >> firstNum >> secondNum;  //moved this here from
//the loop so i got a value

if (firstNum < secondNum)   //first num is smaller
//so i is first num
i = firstNum;
else                       //else second num is smaller
{
i=secondNum;             //sets i to smaller number
secondNum=firstNum;  //sets second number to larger number
firstNum=i;         //copies smaller number from i
}

while (i <= secondNum) //needs to be <= so you get last number
{
if ((i %2) == 0)           //if number is even
evensum += i;
else              //not even, so it's odd
oddsum += i;
i++;
}
return 0;
}``````

There, I fixed the code you had and commented the fixes so you could follow. That should give you a start. It gets you the even/odd sum. If you need more help, let me know.

## Ab000dy_85 -3

good job.
I did not test my code tho.

## carnage 24

Output the numbers and their squares between 1 and 10

here's a way you can do this:

``````int x=1;
cout<<"Squares of numbers between 1-10"<<endl<<endl;
while(x<=10)
{
cout<<"Square of "<<x<<" is "<<x*x<<endl;
x++;
}``````

please analyze the code so you yourself could learn.