Ok I have Visual C++ 2008 and I made a new project and made an app. It's a basic window with a menu, icon, etc. Now I have the following program for instance:

#include <iostream>
#include <math.h>

using namespace std;

int main()
{
    char answer;
    float c, e, x, Derivative;
    
    cout << "\nWhat is the coefficient, exponent, and x; "<< endl << "Seperate each with a space.\t";
    cin >> c >> e >> x;
    
    Derivative = ((c * e) * (pow((x) , (e - 1))));
    
    cout << "\n Your derivative is: " << Derivative << "." << endl << "Thanks for using our program!";
    cout << "\nPress <0> to exit the program:\t";
    cin >> answer;
    if (answer == '0')
    {
        exit(1);
    }
    else
    {
        if (answer != '0')
        {
            main();
        }
    }
    
    return 0;
}

What I want to do is have this run within the window I already have made. SO it will run like it does in command prompt, but in the window: get it? Thanks in advance.

Member Avatar for jencas

I don't understand what you want. Do you want to convert your app to a Windows application??

By the way:

int main()
{
    char answer;
    do {
      float c, e, x, Derivative;
    
      cout << "\nWhat is the coefficient,  exponent, and x; "<< endl << "Seperate each with a space.\t";
      cin >> c >> e >> x;
    
      Derivative = ((c * e) * (pow((x) , (e - 1))));
    
      cout << "\n Your derivative is: " << Derivative << "." << endl << "Thanks for using our program!";
      cout << "\nPress <0> to exit the program:\t";
      cin >> answer;
    } while (answer != '0')
    
    return 0;
}
Member Avatar for jencas

- avoids dangerous recursive call of main()
- removes unnecessary if (answer != '0') in else statement

- avoids dangerous recursive call of main()

In C++, recursive call of main is not allowed at all.

To answer the original question, if you must be able to execute a program that reads from standard input and writes to standard output, you need to investigate input and output redirection (ie. redirecting of stdout to a file, redirecting stdin so input is taken from a file).

Never mind asked my professor, I'll mark this as solved Thanks mates :)

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.