1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Hi, new here, learning C++ on my own, need some help

Discussion in 'C++' started by syraleo, Sep 30, 2009.

  1. syraleo

    syraleo New Member

    Sep 30, 2009
    Likes Received:
    Trophy Points:
    I bought C++ Primer 5th ed , nice book but i'm still confused about functions , prototypes etc. etc. , i googled some articles but i'm still unaware of certain stuff. Seeing as i'm learning it on my own and noone i know does programming, i need help from the folks here. :)

    The script below is suppose to output 2 lines of Three Blind Mice then 2 lines of See how they run. Thing is, if i just follow the textbook i'll just be copying , so i need help understanding the various functions here.

    #include <iostream>  // This is to include the input output stream thing?
    int men();               // This is the prototype for men() ?
    int mice();
    int main()                    // Main body here
          using namespace std;     // to include the standard naming conventions?
          int blind;                      // defining blind as an integer
          int men;
          blind = mice();              // stating blind to the function mice() 
          men = men();               // stating men to the function men()
          cout << x << endl << x << endl;      // straightforward output , 2 lines
          cout << y << endl << y << endl;
          system("PAUSE");                // so i can see the results
          return 0;                 // what is this for to be honest
    int mice(x)                          // defining the function here..
          return x = "Three blind mice\n";   // mice() should contain this string
    int men(y)
        return y = "See how they run.\n";     

    As the above , you can tell i'm unsure of functions and the "return 0;" thing among the other mistakes.

    So here is why i wrote the above as i did:

    1) I defined the prototype(or blueprint as the book says) just below #include <iostream> , which is mice() and men()

    2) I then made it an integer with "int mice;"

    3) Lastly, i defined it as "int mice(x)" with x being the argument , so x is now suppose to assume the string or integer "Three blind mice" and y , "See how they run."

    I have no luck compiling it and the errors devc++ is showing are... not even remotely helpful to say the least.

    I would appreciate any help i can get, thanks.
  2. NewsBot

    NewsBot New Member

    Dec 2, 2008
    Likes Received:
    Trophy Points:
    Good to see such effort and I would try to clarify all I can but I see there are many semantic error which you should understand.

    Return is something where you return the value and way you are doing is all messed up.

    return y = "See how they run.\n";

    What do you mean by this.

    If you want to return an integer it should be

    return 1;

    If you want to return a string

    return "See how they run.\n";

    And then it would work.

    Returning string should be done at later stages of your learning and I would suggest you start with integers. Dont ask why but when you get on basics right you should see on strings.

    Then when you have not defined x, y in main but using it and so the scope of variable is next thing you should know.

Share This Page