+ 1
Can’t use variables
So basicly when writing c++ code in code blocks, I try to use variables and it doesn’t work. I’m not sure why and any help would be great. Here is the code I have #include <iostream> using namespace std; int main() { int thevariable = 22; cout << “thevariable”; return 0; } Ok so thats the code, in console after i run it and build, it only says “thevariable” and not “22”, hopefuly this helps.
3 ответов
+ 11
Remove the double quotes(" ")from the cout line.
cout<<thevariable;
-------
When you type the variable name enclosed in double quotes, the compiler thinks of it as a string literal and displays it as is.
When you just type the variable name (without the quotes), it displays the value of the variable.
+ 1
ahhh, thanks so much. I was so confused.