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!










share|improve this question


















  • 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















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!










share|improve this question


















  • 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













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!










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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














  • 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












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.






share|improve this answer




























    up vote
    2
    down vote













    std::endl is an output-only I/O manipulator. Change your stream input line to just cin >> numbers[i];






    share|improve this answer




























      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.






      share|improve this answer























      • 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











      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














       

      draft saved


      draft discarded


















      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

























      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.






      share|improve this answer

























        up vote
        2
        down vote



        accepted










        std::endl is not a variable to which you could assign a value. So cin >> endl cannot work.






        share|improve this answer























          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.






          share|improve this answer












          std::endl is not a variable to which you could assign a value. So cin >> endl cannot work.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 7 at 22:06









          Stephan Lechner

          24.5k21738




          24.5k21738
























              up vote
              2
              down vote













              std::endl is an output-only I/O manipulator. Change your stream input line to just cin >> numbers[i];






              share|improve this answer

























                up vote
                2
                down vote













                std::endl is an output-only I/O manipulator. Change your stream input line to just cin >> numbers[i];






                share|improve this answer























                  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];






                  share|improve this answer












                  std::endl is an output-only I/O manipulator. Change your stream input line to just cin >> numbers[i];







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 7 at 22:07









                  Blastfurnace

                  13.6k54058




                  13.6k54058






















                      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.






                      share|improve this answer























                      • 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















                      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.






                      share|improve this answer























                      • 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













                      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.






                      share|improve this answer














                      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.







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      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


















                      • 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


















                       

                      draft saved


                      draft discarded



















































                       


                      draft saved


                      draft discarded














                      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





















































                      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







                      這個網誌中的熱門文章

                      Tangent Lines Diagram Along Smooth Curve

                      Yusuf al-Mu'taman ibn Hud

                      Zucchini