c++ - For Loop Not displaying the lowest but the first in the array -


guys, i'm new arrays, i'm making program takes 2 parallel arrays finds both lowest , highest values based on value take highest string array value related integer arrays , outputs related lowest , related highest results on screen.

this have far.

#include<iostream> #include<string> #include<climits>   //prototypes:  using namespace std;  void getjars(string[], int[], int); int gettotal(string[], int[], int); int getlowest(string[], int[], int);   int main() {      string salsa[] = { "mild", "medium", "sweet", "hot", "zesty" };     const int num = 5;     int lowest = 0;     int total = 0;     int jars[num];      getjars(salsa, jars, num);     total = gettotal(salsa, jars, num);     cout << endl << "total of jars sold month: " << total << endl;     lowest = getlowest(salsa, jars, num);     cout << endl << lowest << endl;       return 0; }  void getjars(string salsa[], int jars[], int num) {    cout << "salsa sales calculator...\n"; cout << "------------------------\n";     (int = 0; < num; i++) {          cout << "please insert jar amount each salsa: ";         cout << salsa[i];         cout << " ";         cin >> jars[i];          cout << endl;     }       return; } int gettotal(string salsa[], int jars[], int num) {      int total = 0;      (int = 0; < num; i++) {          total += jars[i];     }      return total; }  int getlowest(string salsa[], int jars[], int num) {      int lowest = jars[0];     string lowsalsa;     (int = 0; < num; i++) {         if(lowest > jars[i])             lowest = jars[i];       return lowest; } 

i'm trying see why gives me first value of array not lowest. please help.

your loop returns on first iteration.

for (int = 0; < 5; i++) {     if(lowest > jars[i])         lowest = jars[i];     return lowest; } 

switch "return" , "}" , should work more correctly. advise using braces if statements well, clarity. nice code.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -