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.
Re: Cout is not displaying text?
1) Please use code tags when posting code. The code you posted is almost unreadable.
2)
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?
Quote:
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)
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.
Quote:
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
Re: Cout is not displaying text?
Quote:
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.
Re: Cout is not displaying text?
Quote:
Originally Posted by
2kaud
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