Thread: Confusion

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    25

    Confusion

    Help please.
    Code:
    #include <iostream>
    
    using namespace std;
    
    int mult(int x,int y);
    
    int main()
    {
        int x;
        int y;
        
        cout<<"Please input two numbers to be multiplied:";
        cin>>x>>y;
        cin.ignore();
        cout<<"The product of these two numbers is:" <<mult (x,y)<<"\n";
        cin.get();
    }
    int mult(int x, int y)
    {
        return x*y;
        
    }
    E:\Programs\Programing\Programs\Function.cpp: In function `int main()':
    E:\Programs\Programing\Programs\Function.cpp:12: error: `cout' undeclared (first use this function)
    E:\Programs\Programing\Programs\Function.cpp:12: error: (Each undeclared identifier is reported only once for each function it appears in.)
    E:\Programs\Programing\Programs\Function.cpp:13: error: `cin' undeclared (first use this function)

    Execution terminated


    is it right?
    Last edited by Nestor; 06-20-2008 at 02:03 PM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    The error will be obvious when it is pointed out... so, do you understand the error messages? They are basically telling you that cout and cin were not declared, but since you included <iostream>, they should be declared, right?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jun 2008
    Posts
    25
    Yes its all good, but now i have question that are not specified in the tutorial,
    what is ionstream, cstdlib and the difference between them.
    Also to go along with that,
    In this code
    Code:
    #include <iostream>
    
    using namespace std;
    
    int mult(int x,int y,int z);
    
    int main()
    {
        int x;
        int y;
        int z;
        
        cout<<"Please input two numbers to be multiplied:";
        cin>>x>>y>>z;
        cin.ignore();
        cout<<"The product of these two numbers is:" <<mult (x,y,z)<<"\n";
        cin.get();
    }
    int mult(int x, int y,int z)
    {
        return x*y*z;
        
    }
    the int<-- in the begining is what tells the whole program that those intergers will be used?
    Is programing all numbers, and input should only be numbers?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    what is ionstream, cstdlib and the difference between them.
    Recall the standard headers are <iostream> and <cstdlib>, not ionstream

    <iostream> gives you access to std::cin and std::cout (and std::cerr and std::clog, and their wide character equivalents). <cstdlib> is the C++ version of <stdlib.h> from C, which gives you access to miscellaneous standard library utilities, including a pseudorandom number generator and C-style memory management functions.

    the int<-- in the begining is what tells the whole program that those intergers will be used?
    No. You may need to read a book, or go through the tutorials slowly. The int that you refer to (if I guessed correctly) declares that the function returns an int.

    Is programing all numbers, and input should only be numbers?
    At some fundamental level, programming is all numbers, but we tend to think at higher levels unless the subject matter specifically concerns numbers.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Nestor View Post
    Yes its all good, but now i have question that are not specified in the tutorial,
    what is ionstream, cstdlib and the difference between them.
    Different headers contain different functions and objects, put simply.
    And it's iostream, not ionstream.

    the int<-- in the begining is what tells the whole program that those intergers will be used?
    I don't know which int you're referring to, but the answer is still false.
    Int is a type that tells the compiler what kind of type a variable is or what a function returns. It's applied to each function and variable, separately.

    Is programing all numbers, and input should only be numbers?
    No. You can input strings, too.
    Although, in the basic computer architecture, strings are treated as numbers, but in a high level environment, they're strings, not numbers.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Terrible confusion with time variables
    By LowlyIntern in forum C++ Programming
    Replies: 12
    Last Post: 08-01-2008, 07:23 AM
  2. C++ Classes: Use, Misuse...Confusion.
    By Snorpy_Py in forum C++ Programming
    Replies: 4
    Last Post: 10-23-2006, 01:46 AM
  3. for loop confusion
    By Enges in forum C++ Programming
    Replies: 6
    Last Post: 04-26-2006, 08:21 AM
  4. Server-net newbie confusion
    By geek@02 in forum Windows Programming
    Replies: 1
    Last Post: 04-28-2005, 02:08 AM
  5. confusion with increment and decrement operators
    By cBegginer in forum C Programming
    Replies: 6
    Last Post: 03-19-2005, 03:45 PM