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

C++programming please i need all codes in this homework . Homework 1) Use an inf

ID: 3583974 • Letter: C

Question

C++programming

please i need all codes in this homework

. Homework

1) Use an infinite loop to print numbers from 1 to 30.

2) Use an infinite loop to print numbers from 10 to 40.

3) Read a number and print its square. Repeat until the number is 0.

Enter a number. 0 to stop.

3

The square of 3 is 9

Enter a number. 0 to stop.

...........

4) Read two number and display the bigger one. Repeat until the two numbers are same.

5) Implement a calculator that provides following menus.

1. add 2. sub 3. mul 4. div 5. quit

select operation

1

enter two numbers

12 22

the sum is 34

1. add 2. sub 3. mul 4. div 5. quit

select operation

3

enter two numbers

10 20

the mul is 200

...............

1. add 2. sub 3. mul 4. div 5. quit

select operation

5

Bye

Explanation / Answer

#include <iostream>
using namespace std;

int main(){
   //part-1
   int t=1;
   for( ; ; ){
       if(t<=30){
           cout<<t<<" ";
           t++;
       }
       else{
           break;
       }
   }

   //part-2
   int u=10;
   for( ; ; ){
       if(u<=40){
           cout<<u<<" ";
           u++;
       }
       else{
           break;
       }
   }

   //part-3
   int n;
   while(true){
       cout<<"Enter a number. 0 to stop.";
       cin>>n;
       if(n==0){
           break;
       }
       else{
           cout<<"The square of "<<n<<" is "<<n*n<<endl;
       }
   }

   //part-4
   int x,y;
   while(true){
       cout<<"Enter two numbers to compare"<<endl;
       cin>>x>>y;
       if(x==y){
           break;
       }
       else if(x>y){
           cout<<x<<endl;
       }
       else{
           cout<<y<<endl;
       }
   }

   //part-5
   while(true){
       cout<<"1. add 2. sub 3. mul 4. div 5. quit"<<endl;
       cout<<"select operation"<<endl;
       int opt;
       cin>>opt;
       cout<<"enter two numbers"<<endl;
       int a,b;
       cin>>a>>b;
       if(opt==1){
           cout<<"the sum is "<<a+b<<endl;
       }
       else if(opt==2){
           cout<<"the sub is "<<a-b<<endl;
       }
       else if(opt==3){
           cout<<"the mul is "<<a*b<<endl;
       }
       else if(opt==4){
           cout<<"the div is "<<a/b<<endl;
       }
       else{
           cout<<"bye";
           break;
       }
   }

   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote