Program Generate for loop, while loop, and do while loop using if and switch functions

Generate a Loops for loop, while loop, and do while loop using if and switch functions

Program Generate for loop, while loop, and do while loop using if and switch functions

Objects: Write a program to generate a Loops for loop, while loop, and do while loop using if and switch functions. C++ Projects.

Code:

#include<iostream>
#include<conio.h>
#include<string>
using namespace std;
void main()
{
char a;
int i=0,f1,id,no,tab;
char whl,ch=0,dow;
float wf=0;
cout<<“Select Your Function.\nUse For Loop press: F\nUse While Loop press: W\nUse Do While Loop press: D\n”;
cin>>a;
if(a==’f’)
{
cout<<“\n :You are in For Loop:\n”;
cout<<” :Table Generator:\n\n”;
cout<<“Enter Any Number: “;
cin>>no;
for(i=1;i<=10;i++)
{
tab=no*i;
cout<<no<<” * “<<i<<“= “<<tab<<endl;
}
}
else if(a==’w’)
{
//while loop start
cout<<“\n :You are in While Loop:\n”;
cout<<“Select Loop function which you perform:\nPress I for Run Int.\nPress F for Run Float.\nPress C for Run Char.\n”;
cin>>whl;
switch(whl)
{
case ‘i’:
while(i<10)
{
cout<<“You are in while loop Int\n”;
i++;
}
break;
case ‘f’:
while(wf<10)
{
cout<<“You are in While Float\n”;
wf++;
}
break;
case ‘c’:
while(ch<10)
{
cout<<“You are in while char\n”;
ch++;
}
break;
default:
cout<<“Invalid selection Please Select given options.”;
break;
}
}
else if(a==’d’)
{
//Do while start
cout<<“\n :You are in Do while Loop:\n”;
cout<<“Select Loop function which you perform:\nPress I for Run Int.\nPress F for Run Float.\nPress C for Run Char.\n”;
cin>>dow;
switch(dow)
{
case ‘i’:
do
{
cout<<“you are in do while loop Int\n”;
i++;
}
while(i<10);
break;
case ‘f’:
do
{
cout<<“you are in do while loop Float\n”;
wf++;
}
while(wf<10);
break;
case ‘c’:
do
{
cout<<“you are in do while loop Char\n”;
ch++;
}
while(ch<10);
break;
default:
cout<<“Invalid selection Please Select given options.”;
break;
}
}
else
{
cout<<“Invalid selection”;
}
getch();
}

Output:

Program Generate for loop, while loop, and do while loop using if and switch functions

Program Generate for loop, while loop, and do while loop using if and switch functions

Program Generate for loop, while loop, and do while loop using if and switch functions

M.A Siddiqui

Hi, I am M.A Siddiqui. I'm a Computer Science Student, In this website, I'm teaching you Multiple languages and provides Projects and other Subjects Notes.

You may also like...

1 Response

  1. June 14, 2020

    […] Program Generate for loop, while loop, and do while loop using if and switch functions […]

Leave a Reply

Your email address will not be published. Required fields are marked *