What's wroing?

This is a discussion on What's wroing? within the C++ Programming forums, part of the General Programming Boards category; I'm like a REAL NEWBIE at C++, and I was wondering what is wrong with this code... Code: #include <iostream.h> ...

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    66

    What's wroing?

    I'm like a REAL NEWBIE at C++, and I was wondering what is wrong with this code...

    Code:
    #include <iostream.h>
    #include <stdlib.h>
    int mult(int x, int y)  
    { 
      return x*y;
    }
    int main()
    {
      mult();
      system("PAUSE");
      return 0;
    }
    An Unofficial Cristiano Ronaldo Website : Ronaldo 7

  2. #2
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    It needs some fixes
    Code:
    #include <iostream>  //
    #include <cstdlib>      // standard c++ headers
    
    int mult(int, int);        //function prototype required before main
    
    int main()
    {
      int product;
      int x = 5;   // 
      int y = 6;   // declare variables x and y and assign values to them
      product = mult(x, y);  // mult() requires two parameters as defined in the prototype
                                        // you want to store the value returned by mult() to product
      system("PAUSE");
      return 0;
    }
    
    int mult(int x, int y)   //function definition
    { 
      return x*y;
    }

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    66
    I was just reading this: http://www.cprogramming.com/tutorial/lesson13.html , and it says that u dun need to use prototype. Anyways, thx!
    An Unofficial Cristiano Ronaldo Website : Ronaldo 7

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,593
    It's not the function prototyping, it's that in your test you forgot to pass arguments to mult(), and it doesnt have default arguments.

  5. #5
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    It looks better because people want to see the program as a whole first, which is the main function, and then the detail, which are the definition of functions called inside main()

  6. #6
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Originally posted by Cris987
    I was just reading this: http://www.cprogramming.com/tutorial/lesson13.html , and it says that u dun need to use prototype. Anyways, thx!
    Also note those tutorials are really out of date, they are pre-C++98 code, so don't pay TOO close attention, especially as they use obsolete headers.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  7. #7
    Registered User
    Join Date
    Nov 2003
    Posts
    66
    thx guys! I just changed my program a bit, but now, nothing happens:
    Code:
    #include <iostream>
    #include <cstdlib>
    int add(int x, int y)  
    { 
      return x+y;
    }
    int main()
    {
     int x = 5;
     int y = 6;
     add(x, y);
      
     system("PAUSE");
     return 0;
    }
    An Unofficial Cristiano Ronaldo Website : Ronaldo 7

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,593
    you need to add some visual feedback, e.g.

    sd::cout << add(x, y) << "\n";

  9. #9
    Registered User
    Join Date
    Nov 2003
    Posts
    66
    i dun really get the sd:: part. I have seen it before somewhere else, but not in this tutorial. As you guys say it, this tutorial does seem outdated. Are there any good ones out there?
    An Unofficial Cristiano Ronaldo Website : Ronaldo 7

  10. #10
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    For a good tutorial get one good book.

  11. #11
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Location
    Mt. Prospect, IL
    Posts
    2,572
    Originally posted by Cris987
    i dun really get the sd:: part. I have seen it before somewhere else, but not in this tutorial. As you guys say it, this tutorial does seem outdated. Are there any good ones out there?
    first of all laserlight meant to say std:: instead of sd::.
    When you're only starting to learn c++ you could just type this underneath your headers:
    Code:
    using namespace std;
    this will let you use all the standard calls from the libraries that you included; cout, cin etc etc.

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  12. #12
    Registered User
    Join Date
    Nov 2003
    Posts
    66
    Originally posted by axon
    first of all laserlight meant to say std:: instead of sd::.
    When you're only starting to learn c++ you could just type this underneath your headers:
    Code:
    using namespace std;
    this will let you use all the standard calls from the libraries that you included; cout, cin etc etc.
    icic...I'm still in need of a good , latest tutorial. Isn't there a good site out there? I really dunno where I can find a programming tutorial book..
    An Unofficial Cristiano Ronaldo Website : Ronaldo 7

  13. #13
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    Originally posted by Cris987
    icic...I'm still in need of a good , latest tutorial. Isn't there a good site out there? I really dunno where I can find a programming tutorial book..
    Barnes and noble, borders, amazon.com. Look for suggested books on this site.

  14. #14
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,593
    yeah, I made a typo, sorry about that.

    Try your local library.
    I think books by SAMS publishing supposedly are pretty good.

  15. #15
    Registered User
    Join Date
    Nov 2003
    Posts
    66
    ookay~ thx!
    An Unofficial Cristiano Ronaldo Website : Ronaldo 7

Page 1 of 2 12 LastLast
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