Cout is not displaying text?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Cout is not displaying text?

  1. #1
    Join Date
    Apr 2013
    Posts
    1

    Cout is not displaying text?

    I'm making a very first program. It's very little more then a simplistic calculator, but i'm having a problem with the cout function. It won't display any text what could the reasons be? any help is appreciated.


    #include <iostream>
    #include <string>
    #include <sstream>
    using namespacestd;

    int main ()
    {
    do
    {
    int(a);
    int(b);
    int(c);
    char(d);
    int number;
    cout << "First number?" << endl; //This is the first line in which the cout does not print.
    getline(cin, number); a=number;
    cout << "Add, Subtract, Multiply, or Divide?" << endl; //It doesnt in any of the following lines either.
    getline(cin, name); d=name;
    cout << "Second number?" << endl;
    getline(cin, number); b=number;
    if (d=add)
    c=a+b;
    cout << c << "\n"; //The only line from which it prints is this one.
    if (d=subtract)
    c=a-b;
    cout << c << "\n";
    if (d=multiply)
    c=a*b;
    cout << c << "\n";
    if (d=divide)
    c=a/b;
    cout << c << "\n";
    }while(1);
    return 0;
    }

    Oh and i'm aware it's still riddled with numerous problems, I just have been working on the cout thing first.

  2. #2
    Join Date
    Apr 1999
    Posts
    27,422

    Re: Cout is not displaying text?

    1) Please use code tags when posting code. The code you posted is almost unreadable.

    2)
    Code:
    if (d=add)
    To test for equality in C++, you use ==, not =.

    3)
    Code:
    int(a);
    int(b);
    int(c);
    char(d)
    What is this supposed to do? Do you have a C++ book or tutorial showing you that this is the way to declare variables?
    Oh and i'm aware it's still riddled with numerous problems, I just have been working on the cout thing first.
    There is nothing wrong with cout. What is wrong is that the other parts of the code are wrong that it affects what is being outputted.

    4)
    Code:
    #include <sstream>
    What's the reason for including this header? You make no use of anything in the sstream header.

    5)
    Code:
    using namespacestd;
    What is "namespacestd"?

    Please do not type in your code. Copy the code (Ctrl-C) directly from your code editor and paste it in the message window (using code tags). Otherwise, we don't know if what you're posting is the actual code you're running or not.
    I'm making a very first program
    You should go back and practice how to make a very simple "Hello World" program and review how to properly declare variables. A "first program" shouldn't consist of do-while loops and if() statements.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; April 14th, 2013 at 02:07 AM.

  3. #3
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,262

    Re: Cout is not displaying text?

    3)
    Code:

    int(a);

    What is this supposed to do? Do you have a C++ book or tutorial showing you that this is the way to declare variables?
    This is actually legal c++ code to define a variable! Unusual and not recommended but syntactically correct.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  4. #4
    Join Date
    Apr 1999
    Posts
    27,422

    Re: Cout is not displaying text?

    Quote Originally Posted by 2kaud View Post
    This is actually legal c++ code to define a variable! Unusual and not recommended bu t syntactically correct.
    Yes, but I can bet that this was not gained or learned from a reputable C++ tutorial or book, at least not one geared to beginners.

    Regards,

    Paul McKenzie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center