Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Write a program that uses while loops to perform the following steps: a. Prom

ID: 671676 • Letter: 1

Question

1. Write a program that uses while loops to perform the following steps:

a. Prompt the user to input two integers: firstNum and secondNum (firstNum must be less than secondNum).
b. Output all odd numbers between firstNum and secondNum.
c. Output the sum of all even numbers between firstNum and secondNum.
d. Output the numbers and their squares between 1 and 10.
e. Output the sum of the square of the odd numbers between firstNum and secondNum.
f. Output all uppercase letters.

Redo using for loops.

Redo using do...while loops.

2. Write a program to implement the algorithm that was designed in the Algorithm Design 7 thread of the Chapter 1 Discussion Forum. Redesign the program so that the user is allowed to buy as many items as desired. Upload the redesigned algorithm and the source code.

Explanation / Answer

#include<iostream.h>

void main()
{
   int firstNum, secondNum,f,s,sum=0,osum=0;

   cout<<"Enter First number";
   cin>>firstNum;
   f=firstNum;
   cout<<"Enter Second number";
   cin>>secondNum;
   s=secondNum;

   if(firstNum>=secondNum)
   {
       cout<<"Pl. Enter First Number less than Second";
       return;
   }
   else
   {
       while(firstNum<=secondNum)
       {
           if(firstNum%2!=0)
           {
               cout<<firstNum<<endl;
               osum=osum+pow(firstNum,2);
           }
           else
           {
               sum=sum+firstNum;
           }
           firstNum++;
       }

       cout<<"sum of all even numbers"<<sum;
        cout<<"sum of square of odd numbers"<<osum;

       firstNum=f;
       secondNum=s;
       sum=0;
       osum=0;

       for(i=firstNum;i<=secondNum;i++)
       {
           if(firstNum%2!=0)
           {
               cout<<firstNum<<endl;
               osum=osum+pow(firstNum,2);
           }
           else
           {
               sum=sum+firstNum;
           }
       }

       cout<<"sum of all even numbers"<<sum;
        cout<<"sum of square of odd numbers"<<osum;

       firstNum=f;
       secondNum=s;
       sum=0;
       osum=0;

       do
       {
           if(firstNum%2!=0)
           {
               cout<<firstNum<<endl;
               osum=osum+pow(firstNum,2);
           }
           else
           {
               sum=sum+firstNum;
           }
           firstNum++;
       }while(firstNum<=secondNum);

       cout<<"sum of all even numbers"<<sum;
        cout<<"sum of square of odd numbers"<<osum;

   }
}