so I am writing a program to prompt the user how many values they would like to input then take those inputs and sort them low to high find average and finally use bool search to see if any of the inputs were equal to an 'A' grade 90 or above after finishing and compiling the program runs but after inputing all the values it just starts outputing there is an A value entered even if there is not and i have to use control c to quit the program please help
#include <iostream>
usingnamespace std;
#include <cstdlib>
int compare(constvoid* pa, constvoid* pb)
{
constint& a = *static_cast<constint*>(pa);
constint& b = *static_cast<constint*>(pb);
if (a < b) return -1;
if (a > b) return 1;
return 0;
}
double getAverage(int* score, int n)
{
int sum = 0;
int i = 0;
for (i = 0; i < n; i++)
sum += score[i];
double average = double(sum) / n;
return average;
}
int main()
{
int size;
cout << "How many scores would you like to record?: ";
cin >> size;
cin.ignore(1000, 10);
int* score = newint[size];
cout << endl;
// read and save the scores
int i;
for (i = 0; i < size; i++)
{
cout << "Enter the scores [" << i << "]: ";
cin >> score[i];
cin.ignore(1000, 10);
cout << endl;
} // for
//use qsort from cstdlib to sort the input values from low to high
qsort(score, size, sizeof(int), compare);
for (i = 0; i < size; i++)
cout << score[i] << ' ';
delete [] score;
cout << endl;
//to find max and min
int max = score[0];
int min = score[0];
for (i = 1; i < size; i++)
{
if (max < score[i]) max = score[i];
if (min > score[i]) min = score[i];
}
cout << endl;
cout << "Minimum = " << min << endl;
cout << "Maximum = " << max << endl;
cout << "Average = " << getAverage(score , size) << endl;
bool found = false;
while (true)
{
if (score[i] >= 90) found = true;
cout << "At least one 'A' grade entered." << endl;
}
if (found)
cout << "No 'A' grade entered." << endl;
cout << endl;
return 0;
} // main
#include <iostream>
usingnamespace std;
#include <cstdlib>
int compare(constvoid* pa, constvoid* pb)
{
constint& a = *static_cast<constint*>(pa);
constint& b = *static_cast<constint*>(pb);
if (a < b) return -1;
if (a > b) return 1;
return 0;
}
double getAverage(int* score, int n)
{
int sum = 0;
int i = 0;
for (i = 0; i < n; i++)
sum += score[i];
double average = double(sum) / n;
return average;
}
int main()
{
int size;
cout << "How many scores would you like to record?: ";
cin >> size;
cin.ignore(1000, 10);
int* score = newint[size];
cout << endl;
// read and save the scores
int i;
for (i = 0; i < size; i++)
{
cout << "Enter the scores [" << i << "]: ";
cin >> score[i];
cin.ignore(1000, 10);
cout << endl;
} // for
//use qsort from cstdlib to sort the input values from low to high
qsort(score, size, sizeof(int), compare);
for (i = 0; i < size; i++)
{ //these brackets were missing
cout << score[i] << ' ';
delete [] score;
cout << endl;
} //these brackets were missing
//to find max and min
int max = score[0];
int min = score[0];
for (i = 1; i < size; i++)
{
if (max < score[i]) max = score[i];
if (min > score[i]) min = score[i];
}
cout << endl;
cout << "Minimum = " << min << endl;
cout << "Maximum = " << max << endl;
cout << "Average = " << getAverage(score , size) << endl;
bool found = false;
while (true)
{
if (score[i] >= 90) found = true;
cout << "At least one 'A' grade entered." << endl;
}
if (found)
cout << "No 'A' grade entered." << endl;
cout << endl;
return 0;
} // main
#include <iostream>
usingnamespace std;
#include <cstdlib>
int compare(constvoid* pa, constvoid* pb)
{
constint& a = *static_cast<constint*>(pa);
constint& b = *static_cast<constint*>(pb);
if (a < b) return -1;
if (a > b) return 1;
return 0;
}
double getAverage(int* score, int n)
{
int sum = 0;
int i = 0;
for (i = 0; i < n; i++)
sum += score[i];
double average = double(sum) / n;
return average;
}
int main()
{
int size;
cout << "How many scores would you like to record?: ";
cin >> size;
cin.ignore(1000, 10);
int* score = newint[size];
cout << endl;
// read and save the scores
int i;
for (i = 0; i < size; i++)
{
cout << "Enter the scores [" << i << "]: ";
cin >> score[i];
cin.ignore(1000, 10);
cout << endl;
} // for
//use qsort from cstdlib to sort the input values from low to high
qsort(score, size, sizeof(int), compare);
for (i = 0; i < size; i++)
cout << score[i] << ' ';
delete [] score;
cout << endl;
//to find max and min
int max = score[0];
int min = score[0];
for (i = 1; i < size; i++)
{
if (max < score[i]) max = score[i];
if (min > score[i]) min = score[i];
}
cout << endl;
cout << "Minimum = " << min << endl;
cout << "Maximum = " << max << endl;
cout << "Average = " << getAverage(score , size) << endl;
bool gradeA = false;
for (i = 0; i < size; i++)
{
if (score[i] >= 90)
{
gradeA = true;
cout << "At least one 'A' grade entered." << endl;
break;
}
if (gradeA)
cout << "No 'A' grades entered." << endl;
break;
}
return 0;
} // main
#include <iostream>
#include <cstdlib>
usingnamespace std;
int compare(constvoid* pa, constvoid* pb)
{
constint& a = *static_cast<constint*>(pa);
constint& b = *static_cast<constint*>(pb);
if (a < b) return -1;
if (a > b) return 1;
return 0;
}
double getAverage(int* score, int n)
{
int sum = 0;
int i = 0;
for (i = 0; i < n; i++)
sum += score[i];
double average = double(sum) / n;
return average;
}
int main()
{
int size;
cout << "How many scores would you like to record?: ";
cin >> size;
cin.ignore(1000, 10);
int* score = newint[size];
cout << endl;
// read and save the scores
int i;
for (i = 0; i < size; i++)
{
cout << "Enter the scores [" << i << "]: ";
cin >> score[i];
cin.ignore(1000, 10);
cout << endl;
} // for
//use qsort from cstdlib to sort the input values from low to high
qsort(score, size, sizeof(int), compare);
for (i = 0; i < size; i++)
cout << score[i] << ' ';
cout << endl;
//to find max and min
int max = score[0];
int min = score[0];
for (i = 1; i < size; i++)
{
if (max < score[i]) max = score[i];
if (min > score[i]) min = score[i];
}
cout << endl;
cout << "Minimum = " << min << endl;
cout << "Maximum = " << max << endl;
cout << "Average = " << getAverage(score , size) << endl;
bool gradeA = false;
for (i = 0; i < size; i++)
{
if (score[i] >= 90)
{
gradeA = true;
cout << "At least one 'A' grade entered." << endl;
break;
}
if (gradeA)
cout << "No 'A' grades entered." << endl;
break;
}
return 0;
} // main
ok i took that an ran it but it still does not say "at least one 'A' grade entered or vice versa when numbers less than 90 or above are input? that is the only problem i am having with the whole entire code? cant figure out how to make it work?
#include <iostream>
#include <cstdlib>
usingnamespace std;
int compare(constvoid* pa, constvoid* pb)
{
constint& a = *static_cast<constint*>(pa);
constint& b = *static_cast<constint*>(pb);
if (a < b) return -1;
if (a > b) return 1;
return 0;
}
double getAverage(int* score, int n)
{
int sum = 0;
int i = 0;
for (i = 0; i < n; i++)
sum += score[i];
double average = double(sum) / n;
return average;
}
int main()
{
int size;
cout << "How many scores would you like to record?: ";
cin >> size;
cin.ignore(1000, 10);
int* score = newint[size];
cout << endl;
// read and save the scores
int i;
for (i = 0; i < size; i++)
{
cout << "Enter the scores [" << i << "]: ";
cin >> score[i];
cin.ignore(1000, 10);
cout << endl;
} // for
//use qsort from cstdlib to sort the input values from low to high
qsort(score, size, sizeof(int), compare);
for (i = 0; i < size; i++)
cout << score[i] << ' ';
cout << endl;
//to find max and min
int max = score[0];
int min = score[0];
for (i = 1; i < size; i++)
{
if (max < score[i]) max = score[i];
if (min > score[i]) min = score[i];
}
cout << endl;
cout << "Minimum = " << min << endl;
cout << "Maximum = " << max << endl;
cout << "Average = " << getAverage(score , size) << endl;
bool gradeA = false;
for (i = 0; i < size; i++)
{
if (score[i] >= 90)
{
gradeA = true;
cout << "At least one 'A' grade entered." << endl;
break;
}
if (max<90) // <-- fixed this
{ // <-- you were missing brackets
cout << "No 'A' grades entered." << endl;
break;
} // <-- you were missing brackets
}
return 0;
}
#include <iostream>
#include <cstdlib>
usingnamespace std;
int compare(constvoid* pa, constvoid* pb)
{
constint& a = *static_cast<constint*>(pa);
constint& b = *static_cast<constint*>(pb);
if (a < b) return -1;
if (a > b) return 1;
return 0;
}
double getAverage(int* score, int n)
{
int sum = 0;
int i = 0;
double average;
for (i = 0; i < n; i++)
{
sum += score[i];
average = double(sum) / n;
}
return average;
}
int main()
{
int size;
cout << "How many scores would you like to record?: ";
cin >> size;
cin.ignore(1000, 10);
int* score = newint[size];
cout << endl;
// read and save the scores
int i;
for (i = 0; i < size; i++)
{
cout << "Enter the scores [" << i << "]: ";
cin >> score[i];
cin.ignore(1000, 10);
cout << endl;
} // for
//use qsort from cstdlib to sort the input values from low to high
qsort(score, size, sizeof(int), compare);
for (i = 0; i < size; i++)
{
cout << score[i] << ' ';
cout << endl;
}
//to find max and min
int max = score[0];
int min = score[0];
for (i = 1; i < size; i++)
{
if (max < score[i]) max = score[i];
if (min > score[i]) min = score[i];
}
cout << endl;
cout << "Minimum = " << min << endl;
cout << "Maximum = " << max << endl;
cout << "Average = " << getAverage(score , size) << endl;
bool gradeA = false;
for (i = 0; i < size; i++)
{
if (score[i] >= 90)
{
gradeA = true;
cout << "At least one 'A' grade entered." << endl;
break;
}
if (max<90) // <-- fixed this
{ // <-- you were missing brackets
cout << "No 'A' grades entered." << endl;
break;
} // <-- you were missing brackets
}
return 0;
}