Learning C++, Need help with part of my code.

Hello Experts,
I'm New to programming and C++.  I've been working on a simple program for learning purposes.  Everything works fine, I'm just adding things and modifying it.  I'm using MS visual C++ 6 for a compiler and when click on Execute program it work fine.  But when I actually  double click the exe, the first question comes up, I input a number then it just flashes and goes away.  Is there a way to have display before the dos window exits?

int main
  int Pennies = 0;
  int OrgPennies  = 0;

  // This program will calculate any amount of Pennies into: $100's, $50's, $20's, $10's , $5's, 1's, Quarters, Dimes, Nickles and the remaining pennies.
  cin >> Pennies;
  // Possible error handling.
  OrgPennies = Pennies,

  // Splitting up the money
  int Bill100 = Pennies/10000;
  Pennies = Pennies%10000;.

  int Bill50 = Pennies/5000;
  Pennies = Pennies%5000;.

  int Bill20 = Pennies/2000;
  Pennies = Pennies%2000;.

  int Bill10 = Pennies/1000;
  Pennies = Pennies%1000;.

  int Bill5 = Pennies/500;
  Pennies = Pennies%1000;.

  int Bill1 = Pennies/100;
  Pennies = Pennies%100;.

  int Coin25 = Pennies/25;
  Pennies = Pennies%25;.

  int Coin10 = Pennies/10;
  Pennies = Pennies%10;.

  int Coin5 = Pennies/5;
  Pennies = Pennies%5;.

  int Coin1 = Pennies/1;
  Pennies = Pennies%1;.

  cout << "For " << OrgPennies << " You will get:" << endl;

  cout << Bill100 << "One Hundred dollar bills" << endl;

  cout << Bill50 << "Fifty dollar bills" << endl;

  cout << Bill20 << "Twenty dollar bills" << endl;

  cout << Bill10 << "Ten dollar bills" << endl;

  cout << Bill5 << "Five dollar bills" << endl;

  cout << Bill1 << "One dollar bills" << endl;

  cout << Coin25 << "Quarters" << endl;

  cout << Coin10 << "Dimes" << endl;

  cout << Coin5 << "Nickels" << endl;

  cout << Coin1 << "Pennies" << endl;

  cout << Pennies << "pennies" << endl;

  return 0;  // program end
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I'd simply suggest running this program from the command prompt.
Before the "return 0" statement, add these three lines:
cout << "Hit enter to continue" << endl;
int unused;
cin >> unused;

system("pause"); also works well for this.
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

super_man_1976Author Commented:
I tried that and it works, but when I hit enter the program doesn't exit.  How would I do that?
well, it is waiting for an input of type integer. so try hitting 3 and then enter. I bet it closes.
system("pause"); will exit no matter what you type (space or otherwise), and cin.getline will exit with the enter key without typing anything else.  Good luck.
I completely agree with mnashadka

Should consider using
system ( "PAUSE" ) ;

You would have to include stdlib.h for the system () call

#include <stdlib.h>


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hi super_man,

if you like staying with the C++ 'cin' you can try  something like

cout << "Hit enter to end prog!" << endl;
char c=0;

but i think either way works fine.
leflon, that could be dangerous. If the user enters more than one character, you could get a gpf, or at least cause a memory fault. If you're going to use getline, you should at least allocate a little bit of space in case the user is trying to screw with you, or just plain dumb, or both.
i understand that this may not be the way it's supposed to be. but it is really dangerous? ok the fail() func returns true after the above getline call, but there is no memory corrupted (as far as i can see). i'm telling getline to just read one char, actually this will become no char at all cause c holds the '\0' after the call.
i'm just curious and like to learn, so is there a problem i don't see right now.

as said, this may not be the best way to do it. it just jumped to my fingers while reading this thread :-)

You're right, I did miss the 1 character thing.  It's been a long morning already.  Sorry about that.  It's not dangerous.
i think i know what you're talking about :-)

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.