C++ Returning two values in Array -
I'm almost with my code; However, one part is not working well enough, just read from a file that contains only numbers (e.g., car sold). Using an array, trying to get the number of maximum, maximum, and maximum index of those numbers. My question is how can I return two values from my MaxSold function? It only adds the maximum to the index, which is not correct. If the result indicates the employee's number then the maximum will be my code so far:
#include & lt; Iostream & gt; # Include & lt; Fstream & gt; Includes / * # & lt; Vector & gt; #include & lt; Iomanip & gt; * / Null read (int arryList [], int size); Zero print (int arryList [], integer shape); Int total (int size list), int size); Int MaxLold (Int Arary List), Int size, int and number); using namespace std; Ifstream Infix ("C: \\ cars.dat"); Int main () {int cars [7]; Int i; Read (Car, 7); Print (car, 7); Cout & lt; & Lt; "Total number of cars sold:" & lt; & Lt; Total (car, 7) & lt; & Lt; "\ N"; Cout & lt; & Lt; "The Max" & lt; & Lt; Maxwell (car, 7, i); } Read zero (int arryList [], int size) {for (int i = 0; i <7; i ++) {inFile & gt; & Gt; ArryList [i]; } Return; } Zero print (int size) {for (int i = 0; i & lt; 7; i ++) {cout & lt; & Lt; I + 1 & lt; & Lt; "-" & lt; & Lt; Array List [i] & lt; & Lt; "\ N"; } Return; } Integer total (int arryList [], integer size) {int sum = 0; For (int i = 0; i gt; max) {max = array list [i]; Related = i + 1; }} Return max, related; }
Use
# include & Lt; Utility & gt; // .. std :: pair & lt; Int, int & gt; MaxSold (Entry List [], int size, int, and number) {// ... return std :: make_pair (max, related); }
Then,
std :: pair and lt; Int, int & gt; P = Maxwell (Cars, 7, I); Std :: Court & lt; & Lt; P.first; // max std :: cout & lt; & Lt; P.second; // related
Comments
Post a Comment