I'm have an assignment to make a simple C++ calculator, but I've hit some kind of snag I can't find. The program accepts all of the input fine, but it doesn't explain any of the results afterwards, it just closes the program. Here's the code:
#include <stdlib.h>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
string name;
float pay;
float hours;
cout << " Hello welcome to the Pay Calculator Program made by: James.\n " ;
cout << " \tPlease enter your name: " ;
cin >> name;
cout << endl;
cout << " \tPlease enter your payrate: ";
cin >> pay;
cout << endl;
cout << " \tPlease enter the hours worked: ";
cin >> hours;
cout << endl;
cout << " \tHello " << name << "!\n";
cout << " \tYou worked " << hours << "hours at $" << pay << "per hour.\n";
cout << " \tYour salary will be $" << hours * pay << ".\n" <<endl;
return 0;
}
What am I missing here? It complies and executes fine, and the debugger says it's fine, I just can't see any of the output.
Posts
return 0;
you'll want to put in a while loop to keep the window open
so, before the last line, put in this piece of code
while(1) {}
return 0;
I'm Jacob Wilson. | facebook | thegreat2nd | [url="aim:goim?screenname=TheGreatSecond&message=Hello+from+the+Penny+Arcade+Forums!"]aim[/url]
A quick workaround is to just stick another line at the end of the app waiting for you to press a key.