What is the coding to loop the program after a key press at the end of the program?

For your original question, you can use a "for" loop or a "while" loop depending on your needs.

for(;;) //infinite until break (or return)
{
   //do stuff here.
}

Please create a new thread for your second question.

For the second question,my best advice to you is this:
you can just use a switch function. if you don't understand, i will explain..
let us assume that the following code is your bmi.cpp:

#include<iostream>
#include<string>
using namespace std;
void show(){
int x=0;
cout<<"Enter the number you want its cube to be shown..";
cin>>x;
x=x*x*x;
cout<<"And this is it.."<<x<<endl;
}

and this is the code for bfp:

#include<iostream>
#include<string>
using namespace std;
void display(){
int x=0;
cout<<"Input the number you want to double..";
cin>>x;
x=x*2;
cout<<"And here it is.."<<x<<endl;
}

and this is the main

#include<iostream>
#include<string>
#include"bmi.cpp"
#include"bfp.cpp"
using namespace std;
int main()
{

 cout<<"Welcome to the bmi/bfp suite!!"<<endl;
cout<<"(1)Bmi,(2)Bfp....choose your choice..";
int choice=0;
cin>>choice;
//invalidity check
if(choice<1|choice>2){
cout<<"Invalid choice!!"<<endl;
return 1;
}
switch(choice)
{
 case 1:
  //Use the functions provided in bmi.cpp
 cout<<"Welcome to the bmi suite!!"<<endl;
 show();
 break;
case 2:
cout<<"Welcome to the bfp suite!!"<<endl;
display();
break;
}
cout<<"Thank you!!"<<endl;
return 0;
}

I hope you understood what I just did. I made use of the functions in bmi.cpp and bfp.cpp at different times using the switch() function.
This is my own advice. Hope this helped

Edited 7 Years Ago by tkud: n/a

This article has been dead for over six months. Start a new discussion instead.