Results 1 to 9 of 9
  1. #1
    crushed's Avatar
    Join Date
    Oct 2009
    Gender
    male
    Location
    My name is Jay. k?
    Posts
    415
    Reputation
    10
    Thanks
    113
    My Mood
    Sneaky

    Cause I'm the only one who's Insomniac.

    Anyways, so yeah. Hai guys, if you know me, then I love you. If you don't well, we can get to know each other. However, , I was reading up on C, yes C, not C++, because I wanna learn C before C++....again.

    Okay, so I'm just starting again, I only did about the intro, yeah it's things I know. But a question came to mind.

    You know how getchar() or cin.get() is used to wait for a char input from the user before it closes? I was wondering if it was possible to use getchar() or cin.get() in an if statement.

    As in, it would ask the user for input, and then if the user inputs a specific character, the program then instead of closing, would skip to the if statement? ._.;

    Something like this is what I'm trying to get at.
    [php]
    int main()
    {
    int x =10;
    cout<< x;
    cin.get();
    if(cin.get() == 2){
    // Do whatever I want here.
    }
    return 0;
    }
    [/php]

    Is this possible? Or what's the other way to do it? I can think of a couple but yeah, this is a question I had.

    Thanks gais. Love yew. ♥

  2. #2
    radnomguywfq3's Avatar
    Join Date
    Jan 2007
    Gender
    male
    Location
    J:\E\T\A\M\A\Y.exe
    Posts
    8,858
    Reputation
    381
    Thanks
    1,823
    My Mood
    Sad
    YEAH

    But, you'd find out faster if you'd just pressed the compile button.



    There are two types of tragedies in life. One is not getting what you want, the other is getting it.

    If you wake up at a different time in a different place, could you wake up as a different person?


  3. The Following User Says Thank You to radnomguywfq3 For This Useful Post:

    Hell_Demon (02-13-2010)

  4. #3
    crushed's Avatar
    Join Date
    Oct 2009
    Gender
    male
    Location
    My name is Jay. k?
    Posts
    415
    Reputation
    10
    Thanks
    113
    My Mood
    Sneaky
    Hmm, thing is though. I tried that with cin.get(), and it.....just fucked up. Lol. o_o As in, instead of getting the value I wanted, it showed me something like #IND 1. Now, I haven't gone to find out what it is, but I'll try getchar. Thanks.

  5. #4
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Did you include namespace std?

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  6. #5
    crushed's Avatar
    Join Date
    Oct 2009
    Gender
    male
    Location
    My name is Jay. k?
    Posts
    415
    Reputation
    10
    Thanks
    113
    My Mood
    Sneaky
    ....Yes I did. Lul.

    And I tried compiling btw, after it displays the value of x, I enter 2 and it closes. ):

  7. #6
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    You do realise that == 2 is not the same as "2" right?
    Ah we-a blaze the fyah, make it bun dem!

  8. The Following User Says Thank You to Hell_Demon For This Useful Post:

    crushed (02-13-2010)

  9. #7
    crushed's Avatar
    Join Date
    Oct 2009
    Gender
    male
    Location
    My name is Jay. k?
    Posts
    415
    Reputation
    10
    Thanks
    113
    My Mood
    Sneaky
    Quote Originally Posted by Hell_Demon View Post
    You do realise that == 2 is not the same as "2" right?
    Oh dear god, I'm forgetting this. >_>; Thanks for that, I realized that mistake. Now, just 1 error left to solve. Thanks Hell_Daddy.

  10. #8
    crushed's Avatar
    Join Date
    Oct 2009
    Gender
    male
    Location
    My name is Jay. k?
    Posts
    415
    Reputation
    10
    Thanks
    113
    My Mood
    Sneaky
    Meh, figured it out. Lul.
    [php]
    #include <iostream>
    #include<conio.h.>
    using namespace std;

    int main()
    {
    int x =10;

    cout<< x;
    if(cin.get() == 'a'){
    cout<<"Hi";
    cin.get();

    // Do whatever I want here.
    }
    /*else
    {
    cout<<"Youlose";
    }
    cin.get();
    */
    return 0;
    }


    [/php]

    Close it if you want Why.

  11. #9
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Well its about time.... >_>

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

Similar Threads

  1. Am I the only one who sees this?
    By InCognito in forum General
    Replies: 68
    Last Post: 06-13-2011, 07:54 AM
  2. Replies: 39
    Last Post: 02-13-2010, 09:35 AM
  3. Replies: 40
    Last Post: 03-17-2009, 02:59 PM
  4. Am i the only one who hates Y!Answers??
    By thechewu in forum Spammers Corner
    Replies: 5
    Last Post: 08-20-2007, 03:27 AM
  5. Am I The Only One?
    By Synns in forum WarRock Korea Hacks
    Replies: 8
    Last Post: 05-20-2007, 01:13 AM