私がしていることについては、負ではない値を受け入れることができ、100より大きくすることはできません。残りのプログラムは、 。私は絶対値を使用するなどのいくつかのことを試しましたが、まだうまく機能しませんでした。どんな助けでも大歓迎です。C++で100以下の正の値のみを受け入れる
#include <iostream>
#include <cmath>
using namespace std;
void getScore(double[]);
double calcAverage(double[]); // Make it a double because you want the exact answer not a rounded one
double findLowest(double[]);
void main() {
\t double scores[5]; // We want to store 5 answers
\t double averageScore, lowestScore;
\t getScore(scores); // Collects the Input
\t averageScore = calcAverage(scores); // The average
\t lowestScore = findLowest(scores); // Finds the lowest score that was put into the array
\t cout << "Here are the Results!" << endl;
\t cout << "The average score was a: " << averageScore << endl;
\t cout << "The lowest score was a : " << lowestScore;
\t cout << endl;
\t cin.ignore();
\t cin.get();
}
void getScore(double scores[])
{
\t for (int i = 0; i < 5; i++) // Will loop 5 times for 5 answers
\t {
\t \t cout << "Enter The Test Score Here?: " << endl;
\t \t cin >> scores[i];// will store the inputs that you enter
\t \t {
\t \t \t if (i > 100)
\t \t \t {
\t \t \t \t cout << "Not a valid answer try again";
\t \t \t \t cin >> scores[1];
\t \t \t }
\t \t }
\t }
}
double calcAverage(double scores[])
{
\t double temp = 0.00; // It's 0.00 because we need decimals
\t for (int i = 0; i < 5; i++)
\t {
\t \t temp += scores[i]; // adding the score values to temp
\t }
\t temp /= 5; // Divides all of the scores by 5 to find the average
\t return temp;
}
double findLowest(double scores[])
{
\t double temp = 0.00;
\t for (int i = 0; i < 5; i++)
\t {
\t \t temp = scores[i];
\t \t if (scores[i - 1] > scores[i]) {
\t \t \t scores[i] = scores[i - 1];
\t \t \t scores[i - 1] = temp;
\t \t }
\t }
\t temp = scores[0]; // Array starts at the lowest value
\t return temp;
}
)(I> 100)'それは(スコア[I]> 100)を ' – JackVanier