integers

Discussion in 'C++' started by AidanPaine, Feb 27, 2009.

  1. AidanPaine

    AidanPaine New Member

    Joined:
    Feb 26, 2009
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Security Guard
    Location:
    NY
    How exactly do you declare integers?
    Do I do it before the cout<<
    and cin>>?
     
  2. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    2
    Trophy Points:
    0
    int i;

    The above statement would declare the variable i of type int
     
  3. AidanPaine

    AidanPaine New Member

    Joined:
    Feb 26, 2009
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Security Guard
    Location:
    NY
    so to declare multiple intergers, I need to do this?

    {
    int x,y,z;
    }
     
  4. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    2
    Trophy Points:
    0
  5. AidanPaine

    AidanPaine New Member

    Joined:
    Feb 26, 2009
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Security Guard
    Location:
    NY
    Then how come my compiler wont run this?


    Code:
    #include <iostream>
    
    using namespace std;
    
    int main ()
    {
     int name;
     
     cout<<"Please input your name: ";
     cin>>name;
     cin.ignore();
     if ( name < 100) {
          cout<<"You have a Horrible name!\n";
     }
    else if ( name == 100) {
         cout<<"YOU ARE MARIO!\n";}
         {
                    int birthdate;
         
         cout<<"PLease enter your birthdate:\n";
         cin>>birthdate;
         cin.ignore();
         if ( birthdate != 002507) {
              cout<<"INVALID. TERMINATION ACTIVATED!:\n";
              }
         else if ( birthdate == 002507) {
              cout<<"Validated. Opening KEY MAKER:\n";
    }
    cin.get();
     
  6. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    2
    Trophy Points:
    0
    What error it gives.

    I can see the main function is never closed though
     
  7. AidanPaine

    AidanPaine New Member

    Joined:
    Feb 26, 2009
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Security Guard
    Location:
    NY
    Its giving me the '}' at end of input
    I think I should know this but, its not clicking in my head.
    And the main never closes?
     
  8. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    2
    Trophy Points:
    0
    Probably at times it needs a fresh pair of eyes to get it done
     
  9. AidanPaine

    AidanPaine New Member

    Joined:
    Feb 26, 2009
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Security Guard
    Location:
    NY
    you mean take a break?
    I tried fixing it and this is what it looks like.
    (I am using a bloodshed DEV-C++ compiler
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main ()
    {
     int name;
     
     cout<<"Please input your name: ";
     cin>>name;
     cin.ignore();
     if ( name < 100) {
          cout<<"You have a Horrible name!\n";
     }
    else if ( name == 100) {
         cout<<"YOU ARE MARIO!\n";}
         {
                    int birthdate;
         
         cout<<"PLease enter your birthdate:\n";
         cin>>birthdate;
         cin.ignore();
         if ( birthdate != 002507) {
              cout<<"INVALID. TERMINATION ACTIVATED!:\n";
              }
         else( birthdate == 002507);{
              cout<<"Validated. Opening KEY MAKER:\n";
    }
    cin.get()';
    and the error message I get is that its missing a terminating charater.
     
  10. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    2
    Trophy Points:
    0
    Use code block for codes in the posts.

    As of now check this line

    cin.get()';

    it should be
    cin.get();

    and then you should add the following as well

    }

    this is something that is apparent an error.

    Also if you get more errors post here and would say how to get them removed.
     
  11. AidanPaine

    AidanPaine New Member

    Joined:
    Feb 26, 2009
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Security Guard
    Location:
    NY
    }
    cin.get();
    }

    This is how it looks again, and its me "expected '}' at end of input
     
  12. AidanPaine

    AidanPaine New Member

    Joined:
    Feb 26, 2009
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Security Guard
    Location:
    NY
    Never mind. I figured it out!!!!
    Thanks Shabbir, you're the best!
     
  13. AidanPaine

    AidanPaine New Member

    Joined:
    Feb 26, 2009
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Security Guard
    Location:
    NY
    And now the program isnt working the way I want it to.
    It compiled alright, but it doesnt work the way I want it to.
    I dont want it to say "invalid terminating program" and then underneath it say "validated"
     
  14. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    2
    Trophy Points:
    0
    Let us know how you wanted it.

    invalid terminating program

    occurs when you have unallocated variable
     
  15. winddomino

    winddomino New Member

    Joined:
    Aug 5, 2009
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Its giving me the '}' at end of input
    I think I should know this but, its not clicking in my head.
    And the main never closes?
    Buy sth cheap, to China Wholesale Mall
     
  16. humridso

    humridso New Member

    Joined:
    Dec 30, 2009
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    can someone help me how to trap keywords in a simple just a simple program..
    i have no idea about his..
    I'm just a newbie here in C++.. i need some introduction for C++..
    hope someone can help me!
    tnx in advance!
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice