Confusion

This is a discussion on Confusion within the C++ Programming forums, part of the General Programming Boards category; Help please. Code: #include <iostream> using namespace std; int mult(int x,int y); int main() { int x; int y; cout<<"Please ...

  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
    21,660
    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?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    21,660
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,554
    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, 02:45 PM

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