皆さん、私は配列の初心者です.2つの並列配列を取るプログラムを作っています。整数配列に関連する最も高い文字列配列値を取り出し、関連する最も低い関連する結果および関連する最も高い関連結果を画面上に出力する。For Loop配列の最初のものは表示されません。
これはこれまで私が行ってきたことです。
#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 This 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";
for (int i = 0; i < NUM; i++) {
cout << "Please Insert the Jar Amount for Each Salsa: ";
cout << salsa[i];
cout << " ";
cin >> jars[i];
cout << endl;
}
return;
}
int getTotal(string salsa[], int jars[], int NUM) {
int total = 0;
for (int i = 0; i < NUM; i++) {
total += jars[i];
}
return total;
}
int getLowest(string salsa[], int jars[], int NUM) {
int lowest = jars[0];
string lowSalsa;
for (int i = 0; i < NUM; i++) {
if(lowest > jars[i])
lowest = jars[i];
return lowest;
}
私はそれは私だけ最低の配列の最初の値を与えていない理由を参照しようとしています。誰かが助けてくれますか?
デバッガを使用する、Luke –
私は実際にはデバッガを使用するように教えられませんでした...どうすればわからない –
次に、デバッガの使い方を学ぶ必要があります。デバッガの使い方を知ることは、すべてのC++開発者にとって必要なスキルです。 –