I'm new to this ;(, whats the problem with this????????

This is a discussion on I'm new to this ;(, whats the problem with this???????? within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream> using namespace std; int main() { char name; cout<<"whats your first initial?"; cin>> name; cout<< name; } ...

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    21

    Exclamation I'm new to this ;(, whats the problem with this????????

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        char name;
        cout<<"whats your first initial?";
        cin>> name;
        cout<< name;
    }
        int ag
    
         cout<<"how old are you?";
        cin>> age;
        if (age==14)
          cout<<"Really?!?  COOL! hehe i'm 14 too";
        if (age==10)
        {
            char letter;
    
            cout<<"Is this my borhter talking? y/n";
            cin>> letter;
            if (letter==y)
              cout<<"Hiya bro!";
            if (letter==n)
              cout<<"Oh, well my brothers 10 too!";
        }
    }
    I can get numbers to work, but I want to get letters to work, my goal here is to figure out how to make it so a person can answer yes or no(well actually just y or n)

  2. #2
    Registered User
    Join Date
    Dec 2010
    Posts
    25

  3. #3
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Should be:
    Code:
    if (letter=='y')
    ...
    if (letter=='n')
    Note the single quotes around the y and n.
    bit∙hub [bit-huhb] n. A source and destination for information.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    And match your braces properly!
    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.

  5. #5
    Registered User
    Join Date
    Oct 2010
    Posts
    18
    More than half of your code is outside of the int main() { } brackets, and is also not within a function declaration or anything for that matter.

    I highly recommend that you slowly *crawl* through the C++ tutorials on this website. Go slow and understand what the reason/purpose for everything in the syntax is.

    http://www.cprogramming.com/reference/
    Last edited by syneii; 12-06-2010 at 03:06 PM.

  6. #6
    Registered User
    Join Date
    Dec 2010
    Posts
    21
    Thanks everbody. I had only been learning for like I day so there were probably a ton of minor formatting errors, but I didn't know why I couldn't get char's to work, now i do so we are all good.

    P.S. I made an awesome calculator thing, and I soooooo proud of myself, haha

  7. #7
    Registered User
    Join Date
    Dec 2010
    Posts
    21
    Oh wow half my code is outside of the main, haha!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM

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