Write a program that uses do...while loops to perform the following steps:
using namespace std;
/*
Write a program that uses do...while loops to perform the following steps:
Prompt the user to input two integers: firstNum and secondNum
(firstNum must be less than secondNum).
Output all odd numbers between firstNum and secondNum.
Output the sum of all even numbers between firstNum and secondNum.
Output the numbers and their squares between 1 and 10.
Separate the numbers by any amount of spaces.
Output the sum of the square of the odd numbers between firstNum and secondNum.
Output all uppercase letters.
*/
int main()
{
int firstNum=0,secondNum=0,n,Sum=0;
// Prompt the user to input two integers: firstNum and secondNum
// (firstNum must be less than secondNum).
while(secondNum<=firstNum)
{
cout<<"\n\tEnter first Number: "; cin>>firstNum;
cout<<"\n\tEnter second Number: "; cin>>secondNum;
cout<<"\n\tSecond Number should be greater than first Number.";
}
// Output all odd numbers between firstNum and secondNum.
cout<<"\n\tOdd Numbers; ";
Sum = 0;
for(n=firstNum;n<=secondNum;n++)
{
if(n%2==1) cout<<n<<", ";
}
// Output the sum of all even numbers between firstNum and secondNum.
cout<<"\n\n\tEven Numbers; ";
for(n=firstNum;n<=secondNum;n++)
{
if(n%2==0) cout<<n<<", ";
}
cout<<"\n\n\tOutput the numbers and their squares between 1 and 10.";
// Separate the numbers by any amount of spaces.
for(n=firstNum;n<=secondNum;n++)
{
if(n<10) cout<<"\n\tNumber = "<<n<<"\tSquare("<<n<<") = "<<n*n;
}
cout<<"\n\n\tOutput the sum of the square of the odd numbers between firstNum and secondNum.";
Sum = 0;
for(n=firstNum;n<=secondNum;n++)
{
if(n%2==1) Sum = Sum + n*n;
}
cout<<"\n\tSum = "<<Sum;
cout<<"\n\tOutput all uppercase letters.\n";
for(n=0;n<26;n++) cout<<char('A'+n)<<" ";
return(0);
}
Comments
Leave a comment