when i test my solution, everything prompts out fine until i get to the point where i need to see the output - everything just disappears and i am not able to see the output. why?
this is my code:
//Ch3AppE03.cpp
//Calculates and displays a commission amount
//Created/revised by Armando Rodriguez on 1/21/2008
#include %26lt;iostream%26gt;
using std::cout;
using std::cin;
using std::endl;
int main()
{
//declare variables
double sales = 0.0;
double rate = 0.0;
double commission = 0.0;
//enter input items
cout %26lt;%26lt; "Enter the sales: ";
cin %26gt;%26gt; sales;
cout %26lt;%26lt; "Enter the commission rate: ";
cin %26gt;%26gt; rate;
//calculate commission
commission = sales * rate;
//display commission
cout %26lt;%26lt; "your commission is $commission" %26lt;%26lt; commission %26lt;%26lt; endl;
return 0;
} //end of main function
C++ Build solution problem?
try puttin a cin%26gt;%26gt; to stop it
after the cout%26lt;%26lt;commission statement
why is endl declared at top, never seen that?
Reply:laptop:~/a$ ./a.out
Enter the sales: 100
Enter the commission rate: .5
your commission is $commission50
No problems under gcc. If you can just change your compiler, you're done.
However, the output line needs to be fixed, as you can see.
It would also be nice to check the validity of the input. As it stands, sales could be "Fred."
Reply:Before the "return 0;" line, put a new line that says this --
system("PAUSE");
This will pause the program so you can see your data before the program closes.
I hope this helps.
Reply:your program is performing well.. dont worry about that...
now, try adding the getch() function before return 0...
but you should include the conio library
your code should look like this:
#include %26lt;iostream%26gt;
#include %26lt;conio%26gt;
...
cout %26lt;%26lt; "your commission is $commission" %26lt;%26lt; commission %26lt;%26lt; endl;
getch();
return 0;
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment