Monday, July 27, 2009

C++ help! when i build the solution and try to test it,....?

the output disappear without letting me check if it's right or not. how can i make it to stay? i am usin microsoft visual studio 2005.





this is my code:





#include %26lt;iostream%26gt;


#include %26lt;iomanip%26gt;





using std::cout;


using std::cin;


using std::endl;


using std::fixed;


using std::setprecision;





int main()


{


//declare variables


int registrants = 0;


int fee = 0;





//enter input


cout %26lt;%26lt; "Enter number of registrants: ";


cin %26gt;%26gt; registrants;





//calculate and display order price





cout %26lt;%26lt; fixed %26lt;%26lt; setprecision(2);





if (registrants %26gt; 0)


{


if (registrants %26gt; 1 %26amp;%26amp; registrants %26lt;= 4)


cout %26lt;%26lt; "Seminar Fee: $" %26lt;%26lt; registrants * 100 %26lt;%26lt; endl;


else if (registrants %26gt;= 5 %26amp;%26amp; registrants %26lt;= 10)


cout %26lt;%26lt; "Seminar Fee: $" %26lt;%26lt; registrants * 80 %26lt;%26lt; endl;


else if (registrants %26gt; 11)


cout %26lt;%26lt; "Seminar Fee: $" %26lt;%26lt; registrants * 60 %26lt;%26lt; endl;


//endifs


}


else


cout %26lt;%26lt; "Invalid Data" %26lt;%26lt;endl;


return 0;


} //end of main function

C++ help! when i build the solution and try to test it,....?
The common solutions seem to be using getch() or system("pause") in the correct place to hold the terminal window open while you examine the output.





If you are not just a Windows drone, a more portable solution is to include and call a function something like the below at the proper point(s) in your program.





// A simple debugging routine to use with DOS console apps to hold the DOS box open


void HoldConsole(void)


{


char hold[3];





cout %26lt;%26lt; "\nHit %26lt;Enter%26gt; ";


cin.getline(hold, sizeof(hold), '\n');


cout %26lt;%26lt; endl;


}
Reply:Put in some wait-for-keyboard-input code to pause the execution.





Hope that helps.
Reply:insert the statement





getch();





one line before return 0; ... and don't forget to include the library conio.h

flash cards

No comments:

Post a Comment