Jump to content

Hello!

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
8 replies to this topic

#1
MerakSpielman

MerakSpielman

    Learning Programmer

  • Members
  • PipPipPip
  • 44 posts
Hi! I'm getting into programming, taking some classes, etc. Figured I'd look around for a programming forum so I could keep up with the community at large. :)

At any rate, I'm mainly learning C++. My classes don't start 'till Friday, but I'm following some online tutorials. The input/output commands, if/else statements, loops, variables, and so forth all seem fairly easy. But then all of a sudden the difficulty ramps up fast. :p

I've seen from reading various threads around here that people have vastly different learning styles for learning a new programming language. I think I'm more of a "set a difficult goal and jump in, finding out what I need to do to achieve it" kind of learner. My current goal is to make a colored square in the center of the screen that will move around when I hit the arrow keys. Don't tell me! I'll figure it out. :D

#2
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Hey MerakSpielman, welcome to CodeCall. I believe I learn in a similar way. I can get only so much knowledge from a book but once I jump in I start learning more rapidly. If you need any help, let us know.

#3
MerakSpielman

MerakSpielman

    Learning Programmer

  • Members
  • PipPipPip
  • 44 posts
hm.... right now I'm trying to figure out why the cin.get(); function is working properly at two places in my program, but not in a third place. It doesn't even stop there and wait for input. Is it somehow skipping that line? How strange...

edit: got it.

#4
MerakSpielman

MerakSpielman

    Learning Programmer

  • Members
  • PipPipPip
  • 44 posts
teehee! This is fun!


#include <iostream>


using namespace std;


int main ()


{

int n1, n2, n3;



  cout << "We are going to add together two numbers! (Press Enter to continue)";

  cin.get(); //this is the command for requesting the user to press enter

  

  while (n3!=0) {

      cout << endl << "All right... what is your first number? ";

      cin >> n1;

      cout << endl << "Very well... " << n1 << " is your first number. Wise choice. What is your second number? ";

      cin >> n2;

      n3 = n1 + n2; //adding the two numbers

      cout << endl << "Really? " << n2 << " is your second number? Truly astonishing!" << endl << endl;

      cout << "When you're ready to see the sum of your numbers, please press Enter.";

  

      if (n3!=0) {

         cin.get();

         cin.get(); //for some reason I had to put the same line in twice to get it to work properly. Not sure why.

         cout << endl << endl << "The sum of " << n1 << " and " << n2 << " is.... " << n3 << "!!!!" << endl << endl;

         cout << "Let's do it again! If you're done adding numbers, just choose 0 and 0 for your numberes, and the program will terminate." << endl << endl;

         }

  }

  return 0;

}


#5
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
Hello MerakSpielman, Welcome to CodeCall!

#6
superjacent

superjacent

    Newbie

  • Members
  • PipPip
  • 11 posts
Welcome aboard. I'm in the same boat as yourself, learning C++.

I know this is the introductory post but since you posted some code it seems like you came across the old 'console will not stay open so at least I can view the results' issue.

I generally put either one of these at the end of the main program:

    // exit routine

    cout << "\n\n...Press ENTER to Exit System...";

    cin.get();

    return 0;

or if that doesn't work, and there are reasons why it wouldn't, I move onto this:
 

   // exit routine

    cout << "\n\n...Press ENTER to Exit System...";

    cin.clear();

    while (cin.get() != '\n')

        continue;

    cin.get();

    return 0;



#7
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
In windows you can use the:

system("PAUSE");


#8
v0id

v0id

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,936 posts
Welcome to CodeCall, MerakSpielman!

#9
TcM

TcM

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 11,147 posts
Welcome to Codecall.

Enjoy your stay