Originally Posted by
Mozza314
Good question. The reason is that when you want the actual character, J, for example, the compiler needs to know that you mean J the character and not J the variable. E.g.:
Code:
int main()
{
int J = 3;
cout << J << endl; // outputs 3
cout << 'J' << endl; // outputs J
return 0;
}
Of course it's conceivable you could make a language in which if there was no variable J available then
would output J the character instead. However, this makes code difficult to read because someone reading it who hasn't seen the whole program will probably expect J stores some value that is being printed. For this reason, in C++ and other languages, you need to put quotes around the letter whenever you mean the letter itself and not a variable.
Yes, I think I understand it now. Thanks Mozza. You have been very helpful through out without any air of arrogance!
Okay, when I use double quotation marks I have text
When I simply enter something, such as A, B, C, etc, it is expected to be a variable.
When I use single quotes then it's a character constant - a constant of special type which has a particular symbol and recognized by the system. But what if I try to use some self-invented character symbol (I see '+' is also taken as a character) which has been standardized by ASCII, then would it give error?
Is this correct? Please correct me if I'm wrong.
Now some more questions. My questions will appear in the code following "//". It would be nice of you if you could shed some light. (sorry, if there is a big issue with indentation, when I copy the code here something goes wrong)
Code:
#include <iostream>
# include <cmath>
#include <cstdlib> // these are header files?
using namespace std; // this is "using" statement?
int main () // this is the function which we are using?
{
float a, b, c, R1, R2; // this is the declaration statement?
system("Color 1A"); // this is what? I use it to change the color of the console.
cout << "Enter a, b, c of the equation ax^2 + bx + c = 0" << endl;
cout << "Enter a = ";
cin >> a; // what are cout and cin statements called?
cout << "Enter b = ";
cin >> b;
cout << "Enter c = ";
cin >> c;
float D = b*b - 4*a*c; // this both declaration and processing statement?
if (D >= 0)
{
cout << "R1 is = " << ( -b + sqrt(D) )/( 2*a ) << endl;
cout << "R2 is = " << ( -b - sqrt(D) )/( 2*a ) << endl;
} // this is if statement?
else
{
cout << "no real roots exist" << endl;
}
system("PAUSE"); // what would called this? "system" specific statement?
}