okay, for some reason, my simple code builds perfect without any errors. however, when i run the code it only runs the first 4 lines of code and then skips the rest and stops there. i seriously don't think its the code either. its completely identical to the one in the book. it doesn't say press any key to continue to finish or anything. This is the simple code too.
#include <iostream>
//using namespace std;
using std::cout;
using std::cin;
using std::endl;
int main ()
{
double currentPay = 0.0;
double raiseRate = 0.0;
double raise = 0.0;
double newPay = 0.0;
cout << "Enter current weekly pay: ";
cin >> currentPay;
cout << "Enter base rate: ";
cin >> raiseRate;
i restarted the projects with console application and empty project. and its set to not set in the properties page.
anybody has any clues to why its not running all the way to cout << "new pay" << newPay << endl;? oh i'm using a vs '05 book, but it shouldn't even matter, right?
wow! really? i knew it had something to do with pausing the system. so disappointed at myself. This is really helpful.. thanks. this didn't happen to me when i first tried it on the 2005 vs before. serious facepalm. thanks again guys
question. but why does the console close even before reading my last line of code before return? is it because it outputs it right away and then goes straight to return 0?
i tried doing the code that you provided on the link. However, when i tried running it, the code still skips the last line of code which was the raise = currentPay * raiseRate.
#include <iostream>
#include <limits>
//using namespace std;
using std::cout;
using std::cin;
using std::endl;
int main ()
{
double currentPay = 0.0;
double raiseRate = 0.0;
double raise = 0.0;
double newPay = 0.0;
cout << "Enter current weekly pay: ";
cin >> currentPay;
cout << "Enter base rate: ";
cin >> raiseRate;
raise = currentPay * raiseRate;
newPay = raise + currentPay;
cout << "New pay: " << newPay << endl;
/*cout << "hello world!";*/
//system("pause"); //keeps window open till you close it
cout << "Press ENTER to continue...";
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n' );
return 0;
now this code gets and outputs what needs to be outputted
1 2 3 4
cout << "Enter current weekly pay: ";
cin >> currentPay;
cout << "Enter base rate: ";
cin >> raiseRate;
now when it gets to the calculation and the last cout to display, the window still closes before it displays it. using the system("pause") statement works just fine. However, i don't want to use that since its not recommended. and i'm trying to use the one suggested by computergeek
1 2
cout << "Press ENTER to continue...";
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n' );
but this didn't work. i'm not sure what is missing with the new one because it still closes before i get to see the last output.
Alternatively, stop messing around trying to trick your IDE into not closing the console it has to open for you and just run your program from the console.