its my first day and i was wondering...

This is a discussion on its my first day and i was wondering... within the C++ Programming forums, part of the General Programming Boards category; its my first day programming in anything... and i was messing with something off of this tutorial (click here) the ...

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

    its my first day and i was wondering...

    its my first day programming in anything...
    and i was messing with something off of this tutorial (click here)

    the point in my modification is to make anything above 60 say you are old and anything below it say you are young
    i got that part working

    after that i decided i wanted to make it so if you say a certian number (66 here)
    that it would respond "moo"

    i dont know what i did wrong though... perhaps someone else with more experiance can help me...

    also... what does iostream mean and why doesnt it work without it... the first guide doesnt say what it is and why it doesnt work without it but it says it doesnt work without it...
    i assume there are other things besides iostream...


    and finally... the code in question
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        int age;
        cout<<"please input your age:";
      cin>> age;  
        cin.ignore();
        if ( age < 60 ) ! ( 66 ) {
                cout<<"you are pretty young \n";
                }
        else if ( age > 60 ) ! ( 66 ) {
                cout<<"you are really old \n";
                }
        else if ( age == 66 ) {
                cout<<"moo \n";
                }
                cin.get();
                }

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    To combine two conditions you need the boolean and operator: &&. Also, to check if something is not equal to something else, you use the not equal operator: !=. So to check for age greater than 60 and not 66, you would use (age > 60 && age != 66).

    <iostream> indicates to your program that you are using stuff from the library that is included in iostream. You can use different standard library headers like <fstream>, <string> or others. In this case, you are using cout and cin from iostream. By including that header, the compiler can look up what cout and cin mean. They are really just variables like age in your code, but they've been declared and defined somewhere else.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    3
    Thanks
    now it works yay...

    is there any way to make it so it uses letters instead of numbers?
    i have olny read those two tutorials so far so if its in a future tutorial just tell me...


    hmm... i just realised there will probably be a conflict at the number 60
    ...

    is there a way i can add a secondary not in on that

    Code:
    (age < 60 && age != 66 && != 99)
    maybe thats right and i have something else messed up though....
    Last edited by tack122; 08-13-2005 at 12:31 AM.

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    Each new condition you add must be complete, so it should be && age != 99.

    You can do it with characters, but be patient, you'll learn that in time.

    As for the conflict at 60, make one of your conditions <= or >= to count the 60.

  5. #5
    Registered User
    Join Date
    Aug 2005
    Posts
    3
    thanks agian

    as for the conflict i just changed one number to 61...

  6. #6
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    also... what does iostream mean and why doesnt it work without it...
    There are certain things your program needs to run without errors. Those things are in a certain file called <iostream>. An #include statement says to replace the #include statement with the contents of the specified file. As a result, <iostream> becomes part of your program.

    Write a simple program that displays "hello world" and even though your program will only be about 5 lines long, you can check the size of your compiled file, and it will be gigantic. That is because <iostream> is included in your program, and it has a lot of stuff in it.

  7. #7
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    More specifically, C++ has no built-in way of dealing with input and output. However, this functionality is built in to the C++ Standard Library, which all standard-compliant compilers must provide. One piece of this library allows you to deal with input and output. The interface for this I/O system is stored in the file <iostream> (and includes such things as cout, cin, cerr, etc). And, the library gets linked in to your program, so that the interface actually "connects" to something.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

Popular pages Recent additions subscribe to a feed

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