how to avoid a value is override for other value in a loop in c++.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • abueno
    New Member
    • May 2009
    • 16

    how to avoid a value is override for other value in a loop in c++.

    cout<<"Do you want to enter another score, enter 'y' or 'n' ?";
    cin>>wish;
    cout<<endl;

    while((wish =='Y')||(wish =='y'))

    {



    cout<<"Enter score: ";
    cin>>scoreu; //double variable that hold any score in the loop.

    counter2++;

    // I want to be able to add scoreu as many times as the user wish, without override the value of scoreu (with the last value of scoreu). Any suggestion....t hanks
  • newb16
    Contributor
    • Jul 2008
    • 687

    #2
    And how are you goning to distinguish them later? e.g. ,
    scoreu assigned 1
    scoreu assigned 2
    ...
    cout << scoreu.
    what will be printed here?

    Comment

    • abueno
      New Member
      • May 2009
      • 16

      #3
      Thank you newb16 for answer...ok
      on the bottom of counter2++;
      // I will put:

      total+=scoreu;

      // And suppose scoreu has many values, like 90, 80, 70; I want the total to be able to add 90 + 80 + 70= 240.
      // Right now scoreu is just registering the last value 70, and the other values like 90 and 80 not.

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        If you want to store more than one value you need more than 1 variable. Traditionally holding more than one of the same type of variable is done with an array, however in C++ you should prefer one of the STL containers, probably vector in this case.

        So I suggest you look up vector in your C++ reference material.

        Comment

        • abueno
          New Member
          • May 2009
          • 16

          #5
          Thank you Banfa, I will look up....

          Comment

          Working...