현재 코드에서 프롬프트를 맨 위에 첨부했습니다. 나는 높은 값이나 낮은 값으로 힘든 시간을 보내고 있습니다. 나는 함수가 내 int main()보다는 오히려 호출되는 문제라고 믿지만 잘못 될 수있다. 가장 낮은 값은 기록되는 값이 아닙니다. 배열의 중간 또는 끝에 기본값이있는 것 같습니다 (6 월 또는 12 월은 내 Low로 출력되는 공통 월 임)배열 및 함수 호출로 카운트를 잃음
이 문제점을 해결할 수있는 방법에 대한 아이디어가 있습니까?
/*
Write a program that lets the user enter the total
rainfall for each of 12 months into an array of
doubles. The program should calculate and display
the total rainfall for the year, the average monthly
rainfall, and the months wit hthe highest and lowest
amounts.
Input Validation: Do not accept negative numbers
for monthly rainfall figures.
*/
include <iostream>
include <iomanip>
include <string>
using namespace std;
//Function Prototypes
double RainTotal(double[], int);
double RainAverage(double[], int);
double RainHighpoint(double[], int);
double RainLowpoint(double[], int);
int main()
{
int count; //counting variable for loops
const int Size = 12;
double RainInput[Size]; //Numerical variables
int RAINHIGHEST, RAINLOWEST;
double RAINTOTAL, RAINAVERAGE;
string Month[] = { "January", "Febuary", "March", "April", //Must list string names for each month
"May", "June", "July", "August", "September", "October",
"November", "December" };
cout << "Please enter the average rainfall with the corresponding month\n\n";
for (count = 0; count < Size; count++)
{
cout << Month[count] << " : "; //User prompted to enter rainfall values
cin >> RainInput[count];
while (RainInput < 0)
{
cout << "Please enter a positive number for " << Month[count] << endl;
cin >> RainInput[count];
}
}
RAINTOTAL = RainTotal(RainInput, Size); //Call Total Rainfall
RAINAVERAGE = RainAverage(RainInput, Size); //Call Average Rainfall
string LowMonth, HighMonth; //String value for given High/Low Months
double LowPoint, HighPoint; //Values stored for highest and lowest rainfall
RAINLOWEST = RainLowpoint(RainInput, Size); //Call Lowest Array Subscript Value
LowMonth = Month[RAINLOWEST];
LowPoint = RainInput[RAINLOWEST];
RAINHIGHEST = RainHighpoint(RainInput, Size); //Call Highest Array Subscript Value
HighMonth = Month[RAINHIGHEST];
HighPoint = RainInput[RAINHIGHEST];
cout << endl << endl;
cout << "The Total Rainfall is: " << RAINTOTAL<<endl;
cout << "The Average Rainfall is: " << RAINAVERAGE << endl;
cout << LowMonth << " had the least rainfall all year with " << LowPoint << endl;
cout << HighMonth << " had the most rainfall all year with " << HighPoint << endl;
return 0;
}
double RainTotal(double RainInput[], int size)
{
double Total = 0;
for (int count = 0; count < size; count++) //Find the Total Rainfall
{
Total += RainInput[count];
}
return Total;
}
double RainAverage(double RainInput[], int size)
{
double Total = 0;
double Average;
for (int count = 0; count < size; count++) //Find the Rainfall Average
{
Total += RainInput[count];
}
Average = Total/size;
return Average;
}
double RainLowpoint(double RainInput[], int size)
{
double LowPoint = RainInput[0];
int LowCount = 0;
for (int count = 0; count < size; count++) //Find Lowest rainfall month through numerical comparison
{
if (RainInput[count] <= LowPoint)
{
LowCount = count;
}
}
return LowCount;
}
double RainHighpoint(double RainInput[], int size)
{
double HighPoint = RainInput[0];
int HighCount = 0;
for (int count = 0; count < size; count++) //Find Highest rainfall month through numerical comparison
{
if (RainInput[count] >= HighPoint)
{
HighCount = count;
}
}
return HighCount;
}
에 오신 것을 환영합니다! 자신의 문제를 여전히 보여주는 [SSCE *] (http://sscce.org/)를 게시하십시오. 또한 코드 내에서 발생하는 상황과 해결 방법에 대해 자세히 설명하십시오. :) – Qix