Why doesn't my program recognize Cin inside a loop in C++?
up vote
0
down vote
favorite
So I'm super new to C++ and I'm trying to get some values from a user ( bunch of numbers), and I want to find the mean median and mode of these numbers. This is how I'm trying to do, but the second cin inside the for loop gets error as
Error C2679 binary '>>': no operator found which takes a right-hand
operand of type 'overloaded-function' (or there is no acceptable
conversion)
#include<iostream>
#include<string>
using namespace std;
int main()
{
int mean, max, min, range = 0;
int numbers[100];
cout << "please enter the range " << endl;
cin >> range;
cout << "please enter the values" << endl;
for (int i = 1; i < range; i++)
{
cin >> numbers[i] >> endl;
}
return 0;
}
thanks!
c++ loops cin cout
add a comment |
up vote
0
down vote
favorite
So I'm super new to C++ and I'm trying to get some values from a user ( bunch of numbers), and I want to find the mean median and mode of these numbers. This is how I'm trying to do, but the second cin inside the for loop gets error as
Error C2679 binary '>>': no operator found which takes a right-hand
operand of type 'overloaded-function' (or there is no acceptable
conversion)
#include<iostream>
#include<string>
using namespace std;
int main()
{
int mean, max, min, range = 0;
int numbers[100];
cout << "please enter the range " << endl;
cin >> range;
cout << "please enter the values" << endl;
for (int i = 1; i < range; i++)
{
cin >> numbers[i] >> endl;
}
return 0;
}
thanks!
c++ loops cin cout
1
The error is in the>> endl
portion of the code.
– natn2323
Nov 7 at 22:06
1
Array indices start at 0, not 1. It might not be a problem here, but it will bite hard eventually.
– chris
Nov 7 at 22:29
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
So I'm super new to C++ and I'm trying to get some values from a user ( bunch of numbers), and I want to find the mean median and mode of these numbers. This is how I'm trying to do, but the second cin inside the for loop gets error as
Error C2679 binary '>>': no operator found which takes a right-hand
operand of type 'overloaded-function' (or there is no acceptable
conversion)
#include<iostream>
#include<string>
using namespace std;
int main()
{
int mean, max, min, range = 0;
int numbers[100];
cout << "please enter the range " << endl;
cin >> range;
cout << "please enter the values" << endl;
for (int i = 1; i < range; i++)
{
cin >> numbers[i] >> endl;
}
return 0;
}
thanks!
c++ loops cin cout
So I'm super new to C++ and I'm trying to get some values from a user ( bunch of numbers), and I want to find the mean median and mode of these numbers. This is how I'm trying to do, but the second cin inside the for loop gets error as
Error C2679 binary '>>': no operator found which takes a right-hand
operand of type 'overloaded-function' (or there is no acceptable
conversion)
#include<iostream>
#include<string>
using namespace std;
int main()
{
int mean, max, min, range = 0;
int numbers[100];
cout << "please enter the range " << endl;
cin >> range;
cout << "please enter the values" << endl;
for (int i = 1; i < range; i++)
{
cin >> numbers[i] >> endl;
}
return 0;
}
thanks!
c++ loops cin cout
c++ loops cin cout
asked Nov 7 at 22:04
ai_boy
44
44
1
The error is in the>> endl
portion of the code.
– natn2323
Nov 7 at 22:06
1
Array indices start at 0, not 1. It might not be a problem here, but it will bite hard eventually.
– chris
Nov 7 at 22:29
add a comment |
1
The error is in the>> endl
portion of the code.
– natn2323
Nov 7 at 22:06
1
Array indices start at 0, not 1. It might not be a problem here, but it will bite hard eventually.
– chris
Nov 7 at 22:29
1
1
The error is in the
>> endl
portion of the code.– natn2323
Nov 7 at 22:06
The error is in the
>> endl
portion of the code.– natn2323
Nov 7 at 22:06
1
1
Array indices start at 0, not 1. It might not be a problem here, but it will bite hard eventually.
– chris
Nov 7 at 22:29
Array indices start at 0, not 1. It might not be a problem here, but it will bite hard eventually.
– chris
Nov 7 at 22:29
add a comment |
3 Answers
3
active
oldest
votes
up vote
2
down vote
accepted
std::endl
is not a variable to which you could assign a value. So cin >> endl
cannot work.
add a comment |
up vote
2
down vote
std::endl
is an output-only I/O manipulator. Change your stream input line to just cin >> numbers[i];
add a comment |
up vote
0
down vote
Instead of cin >> numbers[i] >> endl;
just use cin >> numbers[i];
endl
is used to end the line during an output and is not used with input command like cin
.
Also you can use n
(newline) within ""
, instead of endl
.
For eg: cout << "please enter the range n";
which in my experience is simpler.
endl is used to end the line and flush the stream. Never forget the flush. A very expensive way yo end a line if you don't need to write the stream buffer to the underlying media.
– user4581301
Nov 7 at 22:36
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
std::endl
is not a variable to which you could assign a value. So cin >> endl
cannot work.
add a comment |
up vote
2
down vote
accepted
std::endl
is not a variable to which you could assign a value. So cin >> endl
cannot work.
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
std::endl
is not a variable to which you could assign a value. So cin >> endl
cannot work.
std::endl
is not a variable to which you could assign a value. So cin >> endl
cannot work.
answered Nov 7 at 22:06
Stephan Lechner
24.5k21738
24.5k21738
add a comment |
add a comment |
up vote
2
down vote
std::endl
is an output-only I/O manipulator. Change your stream input line to just cin >> numbers[i];
add a comment |
up vote
2
down vote
std::endl
is an output-only I/O manipulator. Change your stream input line to just cin >> numbers[i];
add a comment |
up vote
2
down vote
up vote
2
down vote
std::endl
is an output-only I/O manipulator. Change your stream input line to just cin >> numbers[i];
std::endl
is an output-only I/O manipulator. Change your stream input line to just cin >> numbers[i];
answered Nov 7 at 22:07
Blastfurnace
13.6k54058
13.6k54058
add a comment |
add a comment |
up vote
0
down vote
Instead of cin >> numbers[i] >> endl;
just use cin >> numbers[i];
endl
is used to end the line during an output and is not used with input command like cin
.
Also you can use n
(newline) within ""
, instead of endl
.
For eg: cout << "please enter the range n";
which in my experience is simpler.
endl is used to end the line and flush the stream. Never forget the flush. A very expensive way yo end a line if you don't need to write the stream buffer to the underlying media.
– user4581301
Nov 7 at 22:36
add a comment |
up vote
0
down vote
Instead of cin >> numbers[i] >> endl;
just use cin >> numbers[i];
endl
is used to end the line during an output and is not used with input command like cin
.
Also you can use n
(newline) within ""
, instead of endl
.
For eg: cout << "please enter the range n";
which in my experience is simpler.
endl is used to end the line and flush the stream. Never forget the flush. A very expensive way yo end a line if you don't need to write the stream buffer to the underlying media.
– user4581301
Nov 7 at 22:36
add a comment |
up vote
0
down vote
up vote
0
down vote
Instead of cin >> numbers[i] >> endl;
just use cin >> numbers[i];
endl
is used to end the line during an output and is not used with input command like cin
.
Also you can use n
(newline) within ""
, instead of endl
.
For eg: cout << "please enter the range n";
which in my experience is simpler.
Instead of cin >> numbers[i] >> endl;
just use cin >> numbers[i];
endl
is used to end the line during an output and is not used with input command like cin
.
Also you can use n
(newline) within ""
, instead of endl
.
For eg: cout << "please enter the range n";
which in my experience is simpler.
edited Nov 8 at 1:18
bcperth
2,0021514
2,0021514
answered Nov 7 at 22:19
Athul Babu
12
12
endl is used to end the line and flush the stream. Never forget the flush. A very expensive way yo end a line if you don't need to write the stream buffer to the underlying media.
– user4581301
Nov 7 at 22:36
add a comment |
endl is used to end the line and flush the stream. Never forget the flush. A very expensive way yo end a line if you don't need to write the stream buffer to the underlying media.
– user4581301
Nov 7 at 22:36
endl is used to end the line and flush the stream. Never forget the flush. A very expensive way yo end a line if you don't need to write the stream buffer to the underlying media.
– user4581301
Nov 7 at 22:36
endl is used to end the line and flush the stream. Never forget the flush. A very expensive way yo end a line if you don't need to write the stream buffer to the underlying media.
– user4581301
Nov 7 at 22:36
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53198562%2fwhy-doesnt-my-program-recognize-cin-inside-a-loop-in-c%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
The error is in the
>> endl
portion of the code.– natn2323
Nov 7 at 22:06
1
Array indices start at 0, not 1. It might not be a problem here, but it will bite hard eventually.
– chris
Nov 7 at 22:29