Note that there are some explanatory texts on larger screens.

plurals
  1. POVector Loop not functioning properly
    primarykey
    data
    text
    <p>I'm trying to write a program that takes 10 people who ate pancakes, and returns the person who ate the most pancakes, I'm using vectors in order to create new elements as the user enters it and return them later, I tried using an array but I was having a harder time. </p> <pre><code>#include &lt;iostream&gt; #include &lt;vector&gt; using namespace std ; int main() { int lnum , input ; int temp = 0; vector &lt;int&gt; persons(10) ; cout &lt;&lt; "This program takes input for 10 people who ate pancakes, \ then checks who ate the most pancakes " &lt;&lt; endl; cout &lt;&lt; "Enter the amount of pancakes each person ate: " &lt;&lt; endl ; cout &lt;&lt; "Person 1: " ; cin &gt;&gt; input ; persons.push_back(input); cout &lt;&lt; "Person 2: " ; cin &gt;&gt; input ; persons.push_back(input); cout &lt;&lt; "Person 3: " ; cin &gt;&gt; input ; persons.push_back(input); cout &lt;&lt; "Person 4: " ; cin &gt;&gt; input ; persons.push_back(input); cout &lt;&lt; "Person 5: " ; cin &gt;&gt; input ; persons.push_back(input); cout &lt;&lt; "Person 6: " ; cin &gt;&gt; input ; persons.push_back(input); cout &lt;&lt; "Person 7: " ; cin &gt;&gt; input ; persons.push_back(input); cout &lt;&lt; "Person 8: " ; cin &gt;&gt; input ; persons.push_back(input); cout &lt;&lt; "Person 9: " ; cin &gt;&gt; input ; persons.push_back(input); cout &lt;&lt; "Person 10: " ; cin &gt;&gt; input ; persons.push_back(input); cout &lt;&lt; endl ; for(int i = 0 ; i &lt; 11; i++){ if(persons.at(i) &gt; temp){ temp == persons.at(i) ; } } cout &lt;&lt; temp &lt;&lt; endl ; return 0 ; } </code></pre> <p>Mostly everything runs fine, except when I run the program, it returns temp as 0, instead of what the actual number should be. Also when I call commands like </p> <pre><code>person.at(1) ; </code></pre> <p>it returns the incorrect value, what I am doing wrong, is this a logical error or syntax?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload