Is there a C++ command that restarts the application. The program I'm making is just a console application that acts like a calculator. But once you enter your number and press enter you have to close the console and re-open it to find another number.

int yes = ;
    int no = ;
    cout<<"Would you like to reset the program to enter new numbers? (Yes or No)\n";
    cin >> yes, no;

what would i have to set the yes and no values to? and is the rest of the code even right?

Is there a C++ command that restarts the application. The program I'm making is just a console application that acts like a calculator. But once you enter your number and press enter you have to close the console and re-open it to find another number.

int yes = ;
    int no = ;
    cout<<"Would you like to reset the program to enter new numbers? (Yes or No)\n";
    cin >> yes, no;

what would i have to set the yes and no values to? and is the rest of the code even right?

I can't clearly understand your tricks with console, but, anyway, here is some code.

int flag = 1;
char c;
while(flag) {
  cout<<"Would you like to reset the program to enter new numbers? (Y or N) ";
  cin>>c;
  if((c=='N')||(c=='n')) flag=0;

  //Code to repeat here
 . . .
}

Say your OS, I'll look fo restarting.

not restarting the computer but just the application

my os is XP

The code you gave me causes the box to constantly repeat Would you like to reset the program to enter new numbers? (Y or N).

so this is the full code right now.

#include <iostream>

using namespace std;
int main ()


{

    float goldennumber, dummy;
    float finalnumber;
    float finalnumber2;
    float ratio = 0.618;
    float ratio2 = 1.618;

    cout<<"Welcome to Easy Golden Ratio Finder!\n";
    cout<<"\n \n";
    cout<<"\tPlease enter a number: ";
    cin >> goldennumber;
    cout<<"\n \n";

    finalnumber = goldennumber * ratio;
    finalnumber2 = goldennumber * ratio2;
    cout<<"\tLarger ratio :\n";
    cout<<"\t\t\t"<< goldennumber <<"  :  "<< finalnumber <<"\n\n";
    cout<<"\tSmaller ratio :\n";
    cout<<"\t\t\t"<< finalnumber2 <<"  :  "<< goldennumber <<"\n\n\n\n";
    cin >> dummy;

    int flag = 1;
    char c;
    while(flag)


    cout<<"Would you like to reset the program to enter new numbers? (Y or N) ";
    cin>>c;
    if((c=='N')||(c=='n')) flag=0;

      //Code to repeat here

    return 0;

}

not restarting the computer but just the application

my os is XP

OK, let's see. You can use this trick:

#include <windows.h>

...

//restart programme
WinExec(prohram_name, SW_SHOW);
exit(1);

...

Try it in YOUR system, if it doesn't work let me know.

Ok im a noob so where should i put that in the code?

Ok im a noob so where should i put that in the code?

#include <iostream>
#include <windows.h>
 
using namespace std;
int main ()
 
 
{
 
    float goldennumber, dummy;
    float finalnumber;
    float finalnumber2;
    float ratio = 0.618;
    float ratio2 = 1.618;
 
    cout<<"Welcome to Easy Golden Ratio Finder!\n";
    cout<<"\n \n";
    cout<<"\tPlease enter a number: ";
    cin >> goldennumber;
    cout<<"\n \n";
 
    finalnumber = goldennumber * ratio;
    finalnumber2 = goldennumber * ratio2;
    cout<<"\tLarger ratio :\n";
    cout<<"\t\t\t"<< goldennumber <<"  :  "<< finalnumber <<"\n\n";
    cout<<"\tSmaller ratio :\n";
    cout<<"\t\t\t"<< finalnumber2 <<"  :  "<< goldennumber <<"\n\n\n\n";
    cin >> dummy;
 
    char c;
    cout<<"Would you like to reset the program to enter new numbers? (Y or N) ";
    cin>>c;
    if((c=='Y')||(c=='y'))  {
        WinExec("programme_name", SW_SHOW);
        exit(1);
    } else {
       //Do if user don't want to restart application

    }

 
     
    return 0;
 
}

programme_name it is a string e.g. "programme.exe".

Maybe it is not very pretty but it works.

Member Avatar for iamthwee

It's like the blind leading the blind...I would have expanded on post # 2 quite frankly.

It works perfectly.

Clear the output with

#incldue <conio.h>

....
clrscr();
...
commented: I'm afraid you are misguided. -2

i get a error. it says clrscr(); is undefined

Have you included conio.h ?

Say your compiler platform.

yeah i included it. the compiler im using is called Code::Blocks

Member Avatar for iamthwee

Why not just do:

#include <iostream>

using namespace std;
int main ()
{
    char c; 
   
    do
    {

    float goldennumber, dummy;
    float finalnumber;
    float finalnumber2;
    float ratio = 0.618;
    float ratio2 = 1.618;

    cout<<"Welcome to Easy Golden Ratio Finder!\n";
    cout<<"\n \n";
    cout<<"\tPlease enter a number: ";
    cin >> goldennumber;
    cout<<"\n \n";

    finalnumber = goldennumber * ratio;
    finalnumber2 = goldennumber * ratio2;
    cout<<"\tLarger ratio :\n";
    cout<<"\t\t\t"<< goldennumber <<"  :  "<< finalnumber <<"\n\n";
    cout<<"\tSmaller ratio :\n";
    cout<<"\t\t\t"<< finalnumber2 <<"  :  "<< goldennumber <<"\n\n\n\n";
    
    cout<<"Would you like to reset the program to enter new numbers? (Y or N) ";
     cin>>c;

    } while ( c == 'y');


    return 0;

}

yeah i included it. the compiler im using is called Code::Blocks

Year conio.h hasn't clrscr in this compiler.

Try

COORD coord;
unsigned long wi;
coord.X=0;
coord.Y=0;

FillConsoleOutputCharacter(GetStdHandle(STD_OUTPUT_HANDLE),  ' ',  80*25, coord, &wi);

Is it works?

nope. FillConsoleOutput undeclared

Sorry:

FillConsoleOutputCharacter

Now OK?

Member Avatar for iamthwee

Nope, you should try my solution, at least it works.

i like iamthwee's solution better but im still trying to find how to clear the text from before from the box after you type 'Y' to restart the app.

How about defining the ENTIRE code a a void function which drops through to the "restart" decision block. If yes, RECALL THE FUNCTION, else return 0; which will drop you out of int main().

I think this solution is more in line with OOP.

The app doesn't restart -- it doesn't terminate until you drop off the end of the main() function.

If you really want to clear the screen, this is how Microsoft does it.

Enjoy.

ok all that does is exit the program how do you get it to exit and start agian without clicking the compile button.

My OS is XP

You've been waiting 4 years to get back to this program?

No wait... First post -- resurrecting an old thread -- for no reason other than stating something doesn't work, but not explaining what doesn't work.

FAIL!!

Start your own thread and ask a real question.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.