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();
}

#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

C++ projects for beginners with source code

2 thoughts on “Program Generate for loop, while loop, and do while loop using if and switch functions”

  1. Pingback: C++ projects for beginners with source code - Codeboks

  2. Simply desire to say your article is as amazing.
    The clearness for your publish is just great and that i can think you’re knowledgeable in this subject.
    Fine together with your permission allow me to snatch your RSS feed to stay updated with approaching post.
    Thanks one million and please continue the enjoyable work.

Leave a Comment

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