Thread: my Code

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    3

    my Code

    ok, i'm trying to learn C++ i don't have any background on Developing languges (if you count HTML and CSS are than i'm only decent at those) so this is my code:
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main() 
    {
        int x
        int y
        
        cout<<"please write this number: ";
        cin>> x;
        cin.ignore();
        cout<<"please re-write the number: ";
        cin>> y;
        
        if (x == y) {
              cout<<"indeed, you have a good memory sir";
              }
              if ( x != y) {
                   cout<<"sir, you have a bad memory";
                   }
                   cin.get();
                   }
    ok don't flame me, this is my first program ever im making on my own! so i'm trying to make a program where you enter the same number twice, but it doesn't work.. i know there's some huge mistake.. so can someone help me out?

  2. #2
    He's trying.
    Join Date
    Apr 2005
    Location
    Missouri, US
    Posts
    70
    You'll need semi-colons after you declare your integers.
    Code:
    int x;
    int y;
    Also, it's good that you're formatting your code with tabs and things, but you might want a system that's a little easier on the eyes in the future.

  3. #3
    Registered User
    Join Date
    Jul 2005
    Posts
    3
    what the..? Wow Thanks a Lot!!

    EDIT: hmm.. it works, but it doesn't work when i put the numbers, right or wrong, the program just closes.. i did some modifications:
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main() 
    {
        int x;
        int y;
        
        cout<<"please write a number: ";
        cin>> x;
        cin.ignore();
        cout<<"please re-write the number: ";
        cin>> y;
        
        if (x == y) {
              cout<<"indeed, you have a good memory sir\n";
              }
              else {
                   cout<<"sir, you have a bad memory\n";
                   }
                   }
    can some one help? again? sorry...
    Last edited by fergalator; 07-29-2005 at 02:01 PM.

  4. #4
    Registered User
    Join Date
    Jul 2005
    Posts
    9
    you can either stick cin.get(); at the end (which you did in your first post, why did you change it?), or run it from the DOS prompt/konsole or whatever you're using.

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    The closing of the console is a common question. In your case, if you add back the cin.get() you'll still need a cin.ignore() before it and after your last call to cin >>.

  6. #6
    Registered User
    Join Date
    Jul 2005
    Posts
    3
    thanks, fixed it!
    it needed a cin.get(); and a cin.ignore();
    Cool! it's Complete now!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  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, 06:05 PM