Beginner, How to loop to the beginning of the program from an IF statement.

  • Thread starter Thread starter PaulYoung666
  • Start date Start date
P

PaulYoung666

Guest
Hey guys, I have been playing around with c++ for about 3 months now. I am not very skilled at the moment ( and certainly not on the level of most people here). I wanted to write a program that would basically calculate d=vt using IF statements ( Displacement= Velocity* Time) and all its variants. The user chooses what they want to solve for. After they choose what they want to solve for, the user inputs their values for D, T, or V depending on what they choose.
What code do I write to allow the users to have a choice between terminating the program, or continuing from the start?

#include <iostream>
using namespace std;
int main()

{
float Di;
float Ve;
float Ti;
int a;
float time;
float displacement;
float velocity;
char choice;

cout << " Hello! Welcome to my basic physics syntax program" << endl;
system ("PAUSE");
cout << " Please choose the values in which you are seeking.
1 Time 5= Displacement 10= Velocity" << endl;

cin >> a;

if ( a < 5 ) {
cout << " You have Chosen to solve for TIME\n";
system ("PAUSE");
cout << " Enter the amount of displacement\n";
system ("PAUSE");
cin >> Di;
cout << " Enter the amount of Velocity\n";
system ("PAUSE");
cin >> Ve;
time = Di/Ve;
cout << " Your time is .. In seconds " << time << endl;
system ("PAUSE");
cout << "Do you want to find other values? (y/n)" << endl;
cin >> choice;}
(choice != n); // What code do I write here to give me the option to terminate the program, or reset the program to the start?


}
else if (a==5) {
cout << " You have chosen to solve for DISPLACEMENT\n";
cout << " Enter the value for Time\n";
system ("PAUSE");
cin >> Ti;
cout << " Enter the amount of Velocity\n";
system ("PAUSE");
cin >> Ve;
displacement = Ve*Ti;
cout << " Your displacement is .. In meters " << displacement << endl;
system ("PAUSE");
cout << "Do you want to find other values? (y/n)" << endl;
cin >> choice;
while(choice != y); // What code do I write here to give me the option to terminate the program, or reset the program to the start?
}
else {
cout << " You have chosen to solve for VELOCITY\n";
cout << " Enter the value for Time\n";
system ("PAUSE");
cin >> Ti;
cout << " Enter the amount of Displacement\n";
system ("PAUSE");
cin >> Di;
velocity = Di/Ti;
cout << " Your velocity is .. In meters per second" << velocity << endl;
system ("PAUSE");
cout << "Do you want to find other values? (y/n)" << endl;
cin >> choice;
while(choice != n); // What code do I write here to give me the option to terminate the program, or reset the program to the start?
}

return 0;
}

Continue reading...
 
Back
Top