Hello everyone. I'm quite new to the programming world, but after few weeks of learning i made a programm that calculates the roots of a quadratic equation,but i can't seem to understand how to get that programm to repeat itself after it is finished, so i don't have to reopen it everytime i need to use it. I would be happy if anyone would write me the solution. BTW if you are wondering what that cin >> i; is doing there, it's there because otherwise the compiler shuts down after the roots are found.
int main()
{
do {
/* Here goes your code */
cout << "Do you want to close your program? Press N if you want to." << endl;
char Answer = 0;
cin >> Answer;
} while (Answer != 'n' && Answer != 'N');
return 0;
}
there are two basic loop structures, for and while.
while is the simpler of the two:
1 2 3 4 5
//while loop
x = 0;
while(/*this remains true*/ x < 10){
x++;// your code here
}
the for loops allows more control over the number of times a loop executes, for example
1 2 3
for(int i = 0/*define a variable*/; i < 10/*same thing here as with while loop*/; i++/*this happens AFTER the code below executes*/){
std::cout << "*" << i;
}
Ok i got how to make a loop in the way you showed, but still i just can't figure out how to make it work in this program . I would like it to ask if you want to restart the program in all 3 situations (with disc> , < or equal to 0). if you have time and ideas, then i would be pleased to see your answer.