-
Illegal character errors
I am sorry my code looks really long but I got some errors in this part that I coudn't really fiqure them out, which they are the following:
[CODE]Warning W8054 Program3.cpp 115: Style of function definition is now obsolete
Error E2316 Program3.cpp 115: 'healthClubMaintain::approvalExerciseToClient()' is not a member of 'healthClubMaintain'
for this part
Code:
void healthClubMaintain::approvalExerciseToClient(exerciseName1){
int flag = 0; // set flag to off
for(int i=0; i<15; i++){
if (names[i] == exerciseName1){
flag = 1;
break ;
}
}
if (flag){
cout<< "Your number is at subscript position " << i << endl;
}
else{
cout<< "Sorry, I could not find your number in this array."<<endl;
}
}
This is my original code
Code:
#include <iostream>
using namespace std;
class healthClubMaintain{
private:
string names[15];
int idnumbers[15];
string exerciseNames[15];
int exerciseidNumbers[15];
int counter,counter2,counter3,counter4,counter5,i,s,q,w,x,z,flag1;
string mystr;
public:
void addClient(string,int);
void printClient();
void printClientID();
void addExercise(string,int);
void healthClubMaintain::printExercise();
void approvalExerciseToClient(string);
healthClubMaintain() { // default constructor
counter5 = 0;
counter4 = 0;
counter3 = 0;
counter2 = 0;
counter=0;
}
};
void healthClubMaintain::addClient(string clientName, int clientIDNumber){
mystr = clientIDNumber;
if (counter<15){
names[counter]=clientName;
counter++;
}
while(counter3<10){
if ( (mystr[counter3] != '1') || (mystr[counter3] != '2') ||(mystr[counter3] != '3') || (mystr[counter3] != '4') ||(mystr[counter3] != '5') || (mystr[counter3]!= '6')||(mystr[counter3] != '7') || (mystr[counter3] != '8')||(mystr[counter3] != '9'))
{
flag1=1;
break;
}
counter3++;
}
if(flag1){
if (counter2<15){
idnumbers[counter2]=clientIDNumber;
counter2++;
}
}
else{
cout << " Error!"<<endl;
}
}
void healthClubMaintain::printClient(){
i=0;
s=0;
while(i<counter){
cout << "client's name: " << names[i]<<endl;
cout << "ID#: " << idnumbers[s]<<endl;
cout << " " <<endl;
i++;
s++;
}
}
void healthClubMaintain::addExercise(string exerciseName, int exerciseNumber){
if (counter4<15){
exerciseNames[counter4]=exerciseName;
counter4++;
}
if (counter5<15){
exerciseidNumbers[counter5]=exerciseNumber;
counter5++;
}
}
void healthClubMaintain::printExercise(){
q=0;
w=0;
while(q<counter4){
cout << "Exercise's name: " << exerciseNames[q]<<endl;
cout << "Exercise#: " << exerciseidNumbers[w]<<endl;
cout << " " <<endl;
q++;
w++;
}
}
void healthClubMaintain::approvalExerciseToClient(exerciseName1){
int flag = 0; // set flag to off
for(int i=0; i<15; i++){
if (names[i] == exerciseName1){
flag = 1;
break ;
}
}
if (flag){
cout<< "Your number is at subscript position " << i << endl;
}
else{
cout<< "Sorry, I could not find your number in this array."<<endl;
}
}
int main(){
int number,loop=0;
int clientIDNumber,exerciseNumber,clientIDA,programNumberA,exerciseNumber1;
string clientName,exerciseName,approvalName,exerciseName1;
healthClubMaintain Club;
while ( loop==0){
cout<< "Select one of the following option:"<<endl;
cout<< "(1) Add a new client to the program"<<endl;
cout<< "(2) Display All clients in the program"<<endl;
cout<< "(3) Add a new exercises in the program"<<endl;
cout<< "(4) Display All exercises in the program"<<endl;
cin >> number;
if ( number ==1 ){
cout << "Insert the client's name" << endl;
cin >> clientName;
cout << "Insert a new ID" << endl;
cin >>clientIDNumber;
Club.addClient(clientName,clientIDNumber);
}
if ( number == 2){
Club.printClient();
}
if ( number == 3){
cout << "Insert the exercise's name" << endl;
cin >> exerciseName;
cout << "Insert a Exercise Number" << endl;
cin >>exerciseNumber;
Club.addExercise(exerciseName,exerciseNumber);
}
if ( number == 4){
Club.printExercise();
}
if ( number == 5){
cout << "Insert the exercise's name" << endl;
cin >> exerciseName1;
cout << "Insert a Exercise Number" << endl;
cin >>exerciseNumber1;
Club.approvalExerciseToClient(exerciseName1);
}
}
}
-
Give the function parameter a type. Move the i declaration out of the loop if you want to use it after the loop. Match up your curly braces.
-
When you see something like this:
Then you have an indentation problem.
Refer to http://cpwiki.sf.net/Indentation for indenting or select all code and press Alt+f8 inside visual studio to indent better.
All arguments must have a type in C++, so you get that error because you omitted the type, hence the compiler skipped the argument but couldn't find a function in the class that takes no arguments.