The code doesn't stay!

This is a discussion on The code doesn't stay! within the C++ Programming forums, part of the General Programming Boards category; Hi, ive just signed up, ive wrote my first C++ program, but it terminates as soon as i enter an ...

  1. #1
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321

    The code doesn't stay!

    Hi, ive just signed up, ive wrote my first C++ program, but it terminates as soon as i enter an interger, plz help me!

    Code:
    #include <iostream>
    using namespace std;
    
    int main ()
    {
      int x;
      cout << "Please enter an interger to continue...";
      cin >> x;
      if (x < 0)
      cout << "You entered a negative number! Program terminated!";
      else if (x > 0)
      cout << "Thank you for participating in this program!" << endl;
      return 0;
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,344
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321
    thank you for trying to help, but i dnt understand

  4. #4
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,383
    Maybe if you read the link provided again?...
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  5. #5
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321
    Yes, thank you, but i want to run it from my compiler/editor

    any ideas?

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,344
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321
    it still doesnt work
    this is the code ive got now...

    Code:
    #include <iostream>
    using namespace std;
    
    int main ()
    {
      int x;
      cout << "Please enter an interger to continue...";
      cin >> x;
      if (x < 0)
      cout << "You entered a negative number! Program terminated!";
      else if (x > 0)
      cout << "Thank you for participating in this program!" << endl;
      cout << "Press enter to continue...";
      cin.get();
      return(0);
    }

  8. #8
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,383
    Place cin.ignore() before the cin.get().

    (it's about time someone changes that FAQ )
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  9. #9
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321
    Yey, thank you it works!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why does old code stay stuck in my console?
    By LLINE in forum C++ Programming
    Replies: 3
    Last Post: 11-12-2008, 06:29 AM
  2. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 10:20 AM
  3. Updated sound engine code
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 11-18-2004, 11:38 AM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 05:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21