geany will not let me use the "endl;" when using c++ [closed] - c++

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
every time I try to compile it I get an error message along the lines of
"exercise3.cpp:10:49: error: expected ‘;’ before ‘endl’"
and if I add the ; before endl I get the error message
"exercise3.cpp:8:71: error: statement cannot resolve address of overloaded function"
I have no idea what the problem is with this, so any help would be appreciated.
code: (sorry about not being lined right but i assure you that it is.)
#include "iostream"
using namespace std;
int main()
{
cout << "hello there!\n";
cout << "here is 5: "<< 5 << "\n";
cout << "the manipulator end1 wrotes a new line to the screen."; endl;
cout << "here is a very bug number:\t" << 70000 endl;
cout << "here is the sum of 8 and 5:\t" << 8+5 endl;
cout << "heres a fraction:\t\t" << (float) 5/8 endl;
cout << "and a very big number:\t" << (double) 70000*70000 endl;
cout << "you really dont have to type this line XD\n";
cout << "or this one :P cause its not really needed!\n";
return 0;
}

You need to insert << before endl.

cout << "the manipulator end1 wrotes a new line to the screen."; endl;
Should be
cout << "the manipulator end1 wrotes a new line to the screen." << endl;
And so on

You need << before each endl.

Related

Why std::endl can't be used after std::cin [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 10 months ago.
Improve this question
What's the diff between \n and endl? Is \n faster?
#include <iostream>
using namespace std;
int main()
{
cout << "Please enter 2 numbers:" << endl;
int a = 0, b = 0;
cin >> a >> b;
cout << "The sum of " << a << " and " << b << " is " << a + b << endl;
return 0;
}
Yes, '\n' is faster here. std::endl will additionally call flush() which is not needed in this case.

How to cout with input in c++? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
Hello guys actually i want to show output with input
e.g:
int main()
int a, b, c;
cin >>a >>b;
c = a-b;
cout <<"Here would be input e.g: 4+5=" << c <<endl;
cout <<"Here would be input e.g: 4-5=" << e <<endl;
If input is in this format a+b and user enter input's then output show after input like this 4+5= and after equal answer would there. Thanx in advance
cout << "Here would be input e.g: " << a << "+" << b<<"=" << c << endl;
cout << "Here would be input e.g: " << a << "-" << b<<"=" << e << endl;
Add the input variables in the cout command as follows:
cout << a << " + " << b<<" = " << c << endl;

C++ outputting weird [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
#include <iostream>
using namespace std;
int main()
{
cout << "*****************************************" <<
endl <<
cout << "Hello All!" <<
endl <<
cout << "Welcome to CSCI-111!!!!!" <<
endl <<
cout << "It is great to see you!" <<
endl <<
cout << "*****************************************" ;
return 0;
}
The first cout is fine and outputs correctly, but every cout after that outputs a strange string of numbers before the words in quotation marks (0x600e88) and my output ends up looking like this
*****************************************
0x600e88Hello All!
0x600e88Welcome to CSCI-111!!!!!
0x600e88It is great to see you!
0x600e88*****************************************
What you currently have:
cout << "blah" << endl << cout << "blah" << endl << cout << ... ;
// ^~~~ ^~~~
You're printing the cout itself, this is what gives you weird numbers.
What you should have:
cout << "blah" << endl;
cout << "blah" << endl;
Or:
cout << "blah" << endl
<< "blah" << endl;
Terminate endls:
cout << "*****************************************" << endl;
cout << "Hello All!" << endl;
cout << "Welcome to CSCI-111!!!!!" << endl;
cout << "It is great to see you!" << endl;
cout << "*****************************************" ;
Or delete the redundant couts:
cout << "*****************************************" << endl <<
"Hello All!" << endl <<
"Welcome to CSCI-111!!!!!" << endl <<
"It is great to see you!" << endl <<
"*****************************************" ;
Otherwise, the expression continues, and you print cout itself, and since it's a function pointer, you print it's address (0x600e88).
In the sequence
cout << "Something" << endl << cout;
the first cout indicates the start of ostream (a stream printing out to the console), while the second one is the part of the stream you want to output, and is treated as a pointer, who outputs what he contains - a numeric address of the call to cout.

Can't use void() [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
i'm having an issue with my C++ code:
#include <iostream>
#include <cmath>
#include <string>
#include <windows.h>
using namespace std;
void displayEnnemyStatus(ennemyAttackPoints, ennemyHealthPoints) // Call this function to display
{ // ennemy related informations
cout << endl << "Ennemy health points: " << ennemyHealthPoints;
cout << endl << "Ennemy attack points: " << ennemyAttackPoints << endl;
}
int main()
{
//Player related variables
int healthPointsMax(100);
int actionPointsMax(100);
int recoveryPoints(100);
int healthPoints(100);
int actionPoints(100);
int attackPoints(100)
//Player related variables
//Ennemy related variables
int ennemyHealthPoints(230);
int ennemyAttackPoints(10);
//Ennemy related variables
//Main variables
string stringInput;
//Main variables
//TEXT
cout << "HP: " << healthPoints << endl;
cout << "AP: " << actionPoints << endl;
cout << "RP: " << recoveryPoints << endl;
cout << endl;
cout << "HP = Health Points, AP = Action Points, RP = Recovery Points" << endl;
cout << endl;
cout << "CONTROLS:" << endl;
cout << "attack [ennemy name] //attacks the ennemy" << endl;
cout << "heal [playername] // heals the selected player" << endl;
cout << endl;
cout << "A wild nugget appears!" << endl;
cout << endl;
cout << "What do you want to do?" << endl;
// TEXT
getline(cin, stringInput);
if (stringInput = attack ennemy)
{
cout << endl << "You dealt 100 attack points to: ENNEMY" << endl;
ennemyHealthPoints = ennemyHealthPoints - attackPoints;
displayEnnemyStatus(ennemyHealthPoints, ennemyAttackPoints);
}
return 0;
}
The debugger says that there is a problem with the fonction "void displayEnnemyStatus"
I checked every variable, there is no problem with that.
Am I doing something wrong?
Try :-
if (stringInput == "attack ennemy")
{
cout << endl << "You dealt 100 attack points to: ENNEMY" << endl;
ennemyHealthPoints = ennemyHealthPoints - attackPoints;
**displayEnnemyStatus(ennemyAttackPoints, ennemyHealthPoints)**;
}
Instead of :-
if (stringInput = attack ennemy)
{
cout << endl << "You dealt 100 attack points to: ENNEMY" << endl;
ennemyHealthPoints = ennemyHealthPoints - attackPoints;
displayEnnemyStatus(ennemyHealthPoints, ennemyAttackPoints);

error: expected primary-expression before ‘;’ token [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
First time in a computer science class. First lab assignment. Wrote exactly what the teacher wrote, yet it wont compile, and neither the teacher or I can figure out why. Please help. Thank you.
#include <iostream>
#include <string>
using namespace std;
int main ()
{
int number;
string residence;
//Just an example of a comment
cout << "Hello. Welcome to CSCI-1!" endl;
cout << "Spring 2014" endl;
cout << "please enter a number: " endl;
cin >> number;
cout << "you entered the number: " << number <<endl;
cout<<"Please enter your state of residence: " endl;
cin>>residence;
cout <<"you stated you live in " << residence <<"." <<;
return 0;
}
Errors:
lab01.cpp: In function ‘int main()’:
lab01.cpp:11: error: expected ‘;’ before ‘endl’
lab01.cpp:12: error: expected ‘;’ before ‘endl’
lab01.cpp:14: error: expected ‘;’ before ‘endl’
lab01.cpp:19: error: expected ‘;’ before ‘endl’
lab01.cpp:21: error: expected primary-expression before ‘;’ token
You are missing the << operator before the endl constructs. Change
cout << "Hello. Welcome to CSCI-1!" endl;
To
cout << "Hello. Welcome to CSCI-1!" << endl;
In addition to the missing << before endl (in several lines), you also have an extra one on a line:
cout <<"you stated you live in " << residence <<"." <<;
^^ -- extra!
This will cause you to get another compiler error once you fix the first one. It should be:
cout <<"you stated you live in " << residence <<"." << endl;
or
cout <<"you stated you live in " << residence <<".";