How to restart my program

Hi i want to make my program to restart after displaying the last output. Can anyone please help me as im new in this thing. all helps are really appreciated. thanks

#include <iostream>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <stdlib.h>
using namespace std;

int main (int argc, char *argv[])


{
int V = 100, R = 100, freq, a, b = 180, minFreq, maxFreq, intvFreq;
float L = 10e-3, C = 10e-6, PI=3.142, anglepol, polZ, Ipol, cart_a, cart_b;
float xL, xC;
char quit, restart;
while (quit != 'q')




{
cout << "\n This is a series RLC circuit program to calculate the current of the circuit\n" << endl;
cout << "\t in Polar and Cartesian form ( 100Hz to 2KHz)\n" << endl;
cout << "\t----R = 100 ohm-------L = 10mH--------C = 10uF------" << endl;
cout << "\t| |" << endl;
cout << "\t--------------AC supply = 100V/45deg----------------" << endl;



cout << "\n Please enter the minimum frequency: \n" ;
cin >> minFreq ;

cout << "\n Please enter the maximum frequency: \n" ;
cin >> maxFreq ;

cout << "\n Enter the frequency interval: \n";
cin >> intvFreq ;

cout << endl << "\n\tFrequency Hz\tCurrent\t\t\tCurrent" << endl;
cout <<"\t Polar\t\t\tCartesian\n";
cout <<"\t (current,deg)\t\t (a+bi)\n" <<endl;
for (freq=minFreq; freq<=maxFreq; freq=freq+intvFreq)

{
xL = 2*PI*freq*L;
xC = 1/(2*PI*freq*C);
anglepol = (atan((xL-xC)/R))* b/PI;
//cart Z = complex(r , xL - xC);
//I = V/Z;
polZ = sqrt((R*R)+((xL - xC)*(xL - xC)));
Ipol = V/polZ;

cart_a = Ipol * cos(anglepol);
cart_b = Ipol * sin(anglepol);


printf ("\t%d\t\t%3.2f,%3.2f\t\t%3.2f,%3.2fi\n", freq, Ipol, anglepol, cart_a, cart_b);


}


cout << "\n\n \t\t Press r to restart the program" << endl;
cout << "\n \t\t\t\t or " << endl;
cout << "\n \t\t Press q to quit the program" << endl;







cin >> quit;

}


system("cls");
}

You could use a do-while. Which means you have to place all the code in your main, in a do-while loop. After you do that make the condition for the do-while, true, and it'll restart your program. =]
Last edited on
thats the idea i got applying do-while but i dont know how to put the condition, is there any examples i can refer to?
im have sort out on how to restart the program. the next case is how im gonna make it only certain key will execute the restart?
math.h -> cmath
stdio.h -> not need iostream is the same thing
stdlib.h -> cstdlib

could you please explain "int argc, char *argv[]" because I can find nothing that will tell me
could you please explain "int argc, char *argv[]" because I can find nothing that will tell me

I think that is the traditional command line arguments for C/C++ main function. As long as your command-line C/C++ program has a main function that need to take in command line arguments, it is retrieved via these two parameters.

char *argv[] can also be rewritten as char **argv
Topic archived. No new replies allowed.