These are the instructions for my project:
4. You will need to write a program that has three functions and performs the following:
(a) asks the user to enter the number of scores that will be entered
(b) while you ll up a scores array with that many scores, continue to ask the user to enter
a score value, save it as a char array and validate the input
(c) validate means that you will check the the value entered for each score: that it is not
negative or has anything else but digits.
(d) once you have done this validation on the char array containing the user's input, convert
it to integers and save this valid value to scores array
(e) once the array of scores is lled, calculate the average of all the scores, and print to the
screen the following:
Total number of scores entered:
Sum of all scores entered:
Average of all the scores entered:
here is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
#include <iostream>
#include <cctype>
using namespace std;
bool isNum(char[]);
bool inRange(int);
bool isNeg(char[]);
int main(){
char input[10], numberofscores[10];
int numberscores, currentnumberscores=0, score=0;
cout << "How many scores are you going to enter? ";
cin >> numberofscores;
while((isNeg(numberofscores)==1)||(isNum(numberofscores)==1))
{
cout << "You have entered an invalid number." << endl;
cout << "How many scores are you going to enter? ";
cin >> numberofscores;
}
numberscores = atoi(numberofscores);
int scorearray[numberscores], sum=0;
while(currentnumberscores < numberscores)
{
cout << "Enter score " << (currentnumberscores+1) << ": ";
cin >> input;
bool isNegative = isNeg(input);
isNeg();
if(isNegative == true){
cout << "You have entered a negative number. Please try again." << endl;
cout << "Enter score " << (currentnumberscores+1) << ": ";
cin >> input;
}
bool isNumber = isNum(input);
isNum();
if(isNumber == false){
cout << "You have entered characters with the numers. Please try again." << endl;
cout << "Enter score " << (currentnumberscores+1) << endl;
cin >> input;
}
bool isRange = inRange(input);
inRange();
if(isRange == false){
cout << "You have entered a number that is too high or too low. Please try again." << endl;
cout << "Enter score " << (currentnumberscores+1) << endl;
cin >> input;
}
}
for(int b = 0; b < input; b++){
sum = sum + input[b];
}
cout << "The sum of the scores entered : " << sum <<endl;
cout << "The average of the scores entered is: " << (sum)/(input) << endl;
bool isNum(char in[]){
int k = 0;
bool numbers;
while(in[k] != '\0){
if(isdigit(in[k])){
numbers = true;
}
else{
numbers = false;
break;
}
k++;
}
return numbers;
bool isNeg(char a[]){
int l = 0;
bool negatives;
while(a[l] != '\0'){
if(isalpha(a[l]){
negatives = false;
}
else{
negatives = true;
break;
}
l++;
}
return negatives;
bool inRange(char r[]){
int p = 0;
bool ranges;
while(r[p] != '\0'){
if(0 < r[p] < 105){
ranges = true;
else{
ranges = false;
break;
}
p++;
}
return ranges;
}
}}}
|
and i keep getting these errors:
7 too few arguments to function `bool isNeg(char*)'
33 at this point in file
5 too few arguments to function `bool isNum(char*)'
40 at this point in file
47 `isRange' undeclared (first use this function) (Each undeclared identifier is reported only once for each function it appears in.)
47 cannot convert `bool (*)(int)' to `const char*' for argument `1' to `int atoi(const char*)'
48 invalid conversion from `char*' to `int'
48 initializing argument 1 of `bool inRange(int)'
6 too few arguments to function `bool inRange(int)'
49 at this point in file
57 ISO C++ forbids comparison between pointer and integer
61 invalid operands of types `int' and `char[10]' to binary `operator/'
63 expected `,' or `;' before '{' token
66 missing terminating ' character
76 `numbers' undeclared (first use this function)
78 a function-definition is not allowed here before '{' token
78 expected `,' or `;' before '{' token
Please help, don't know what is wrong or what I am doing wrong.