Not compiling, errors

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.
The errors tell you what is wrong. Look at your code where you call your 'isNeg' function. You declared it as taking a char[] parameter. You are calling it without any parameters. Looks like you actually call it right then for some reason have another incorrect call to the function (without a parameter) on the next line.

Same with isNum().

Same with inRange().

Another thing, you are including your function implementations within the body of main(). This is incorrect. They should be implemented outside of main().

On line 66 you are missing a '
 
while(in[k] != '\0){ 

should be...
 
while(in[k] != '\0'){


You've got some editing to do.
Well you can read, can't you ? :)

7 too few arguments to function `bool isNeg(char*)'
33 at this point in file

You go to line 33 and you see isNeg(); and your function is declarated as bool isNeg(char[]);

And you don't have to open multiple topics( http://www.cplusplus.com/forum/beginner/36422/ )
Okay, thank you for your help. I just have a couple errors left that I can't fix. Please help. 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
109
110
111
112
113
114
115
116
// poefjeg.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <cctype>
using namespace std;

bool isNum(char[]);
bool inRange(int);
bool isNeg(char[]);

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;
     
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;
     }                                 
     
}}}



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);
bool isNeg(char[]);
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);
bool isNum(char[]);
if(isNumber == false){
cout << "You have entered characters with the numers. Please try again." << endl;
cout << "Enter score " << (currentnumberscores+1) << endl;
cin >> input;
}

int isRange = atoi(inRange);
bool isRange = inRange(input);
bool inRange(int[]);
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;
}
scorearray[currentnumberscores]=atoi(input)
currentnumberscores++;
}

for(int b = 0; b < numberscores; b++){
sum = sum + scorearray[b];
}
cout << "The sum of the scores entered : " << sum <<endl;
cout << "The average of the scores entered is: " << (sum)/(numberscores) << endl; 


these are the errors:

1>(28) : error C2144: syntax error : 'char' should be preceded by ')'
1>(28) : error C2660: 'isNeg' : function does not take 0 arguments
1>(28) : error C2059: syntax error : ')'
1>(28) : error C2143: syntax error : missing ';' before '{'
1>(31) : error C2065: 'a' : undeclared identifier
1>(31) : fatal error C1903: unable to recover from previous error(s); stopping compilation

thank you for your help
Is "isNeg" a function? If so, it needs an identifier (int, void ect...)

The variable 'a' needs an identifier (int, char ect...)
if i put a bool before "isNeg" i get a lot of more errors. and how come i have to put an identifier for a but i didn't have to for "in" or for "r" for the other (char [])
Your braces are messed up. You have isNeg and inRange in the isNum function.


EDIT: Okay, i fixed now, but now with this code, i have this error
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
109
110
#include <iostream>
#include <cctype>
using namespace std;

bool isNum(char[]);
bool inRange(int);
bool isNeg(char[]);

{
     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;
     
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;
     }  
                              
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);
bool isNeg(char[]);
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);
bool isNum(char[]);
if(isNumber == false){
cout << "You have entered characters with the numers. Please try again." << endl;
cout << "Enter score " << (currentnumberscores+1) << endl;
cin >> input;
}

int isRange = atoi(inRange);
bool isRange = inRange(input);
bool inRange(int[]);
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;
}
scorearray[currentnumberscores]=atoi(input)
currentnumberscores++;
}

for(int b = 0; b < numberscores; b++){
sum = sum + scorearray[b];
}
cout << "The sum of the scores entered : " << sum <<endl;
cout << "The average of the scores entered is: " << (sum)/(numberscores) << endl; 
}}}}


and i get this error:

9 expected unqualified-id before '{' token
9 expected `,' or `;' before '{' token


Last edited on
The first brace of a function must be paired with an ending brace at the end of that function, BEFORE the next function, as follows:

void functionA ()
{
cout<< "something\n";
}

void functionB ()
{
cout<< "something else\n";
}

void main ()
{
functionA();
functionB();
}
Also, line 29 (isalpha(a[]) needs another bracket, (isalpha(a[])).
What is the purpose of the code on lines 79, 86, and 95 in last posted code?

I reformatted your code a little to make it more readable. This should help you identify some of the errors. I didn't make any corrections to the code, just lined things up a little better so you can see more clearly what is going on.
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include <iostream>
#include <cctype>
using namespace std;

bool isNum(char[]);
bool inRange(int);
bool isNeg(char[]);

{
     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;

     
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;
}  
                              
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);
    bool isNeg(char[]);

    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);
    bool isNum(char[]);

    if(isNumber == false)
    {
      cout << "You have entered characters with the numers. Please try again." << endl;
      cout << "Enter score " << (currentnumberscores+1) << endl;
      cin >> input;
    }

    int isRange = atoi(inRange);
    bool isRange = inRange(input);
    bool inRange(int[]);

    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;
    }

    scorearray[currentnumberscores]=atoi(input)
    currentnumberscores++;
  }

  for(int b = 0; b < numberscores; b++)
  {
    sum = sum + scorearray[b];
  }

  cout << "The sum of the scores entered : " << sum <<endl;
  cout << "The average of the scores entered is: " << (sum)/(numberscores) << endl; 
}
}
}
}
Last edited on
Topic archived. No new replies allowed.