||=== car project, Debug ===|
/home/rej3kt/Desktop/car_class/car project/car.cpp|7|error: declaration of ‘Customer::Customer(char*, char*, int, char*, float)’ outside of class is not definition|
/home/rej3kt/Desktop/car_class/car project/car.cpp|8|error: expected unqualified-id before ‘{’ token|
/home/rej3kt/Desktop/car_class/car project/car.cpp|49|error: prototype for ‘void Customer::setPcode(char)’ does not match any in class ‘Customer’|
/home/rej3kt/Desktop/car_class/car project/car.h|25|error: candidate is: void Customer::setPcode(char*)|
||=== Build finished: 4 errors, 0 warnings ===|
#include <iostream>
#include <string.h>
#include "car.h"
#include <cstdlib>
#include <fstream>
usingnamespace std;
int main()
{
char cust_name[50];
char cust_gender[50];
int cust_phone;
char cust_pcode;
float cust_dob;
int number;
char username[50];
Customer c1(cust_name, cust_gender, cust_phone, cust_pcode, cust_dob);
cout << " Please enter your name to start: "<<endl;
cin.getline(username, 50);
do{
cout << "\n\n\nWelcome, please enter a number to go to that section on the menu:\n1) Enter your car name"<<endl;
cout << "2) Enter your car colour" << endl;
cout << "3) Enter the age of your age"<<endl;
cout << "4) Enter the value of your car in GBP"<<endl;
cout << "5) Enter how many miles per gallon your car does"<<endl;
cout << "6) Save any informaion entered" <<endl;
cout << "7) Retrieve any previously entered information" <<endl;
cout << "8) Exit program"<<endl;
cin >> number;
ofstream myfile;
switch (number){
case 1:
cout << "Enter your car name: " << endl;
cin >> cust_name;
c1.setName(cust_name);
break;
case 2:
cout << "Enter your car colour: " << endl;
cin >> cust_gender;
c1.setGender(cust_gender); break;
case 3:
cout << "Enter the age of your car: " << endl;
cin >> cust_phone;
c1.setPhone(cust_phone); break;
case 4:
cout << "Enter the value of your car in GBP: " << endl;
cin >> cust_pcode;
c1.setPcode(cust_pcode);
break;
case 5:
cout << "Enter how many miles per gallon your car does: " << endl;
cin >> cust_dob;
c1.setDob(cust_dob); break;
case 6:
cout << "Saved!"<<endl;
myfile.open ("class2.txt");
myfile << c1.getName() << endl;
myfile << c1.getGender() << endl;
myfile << c1.getPhone() << endl;
myfile << c1.getPcode() << endl;
myfile << c1.getDob() <<endl;
myfile.close();
break;
case 7:
break;
case 8:
cout << "Press enter to close"<<endl;
break;
return 0;
}
}while(number !=8 );
cout << "\n\n\n\n\n\n\n\n\n" ;
cout << "Your car name is: " << c1.getName() <<endl;
cout << "Your car colour is: " << c1.getGender() <<endl;
cout << "Your car is " << c1.getPhone() << " years old"<<endl;
cout << "Your car is worth £" <<c1.getPcode() <<endl;
cout << "Your car does " <<c1.getDob()<< "mpg"<<endl;
return 0;
}
and the errors:
1 2 3 4 5 6 7
/home/rej3kt/Desktop/car_class/car project/main.cpp||In function ‘int main()’:|
/home/rej3kt/Desktop/car_class/car project/main.cpp|17|error: invalid conversion from ‘char’ to ‘char*’|
/home/rej3kt/Desktop/car_class/car project/main.cpp|17|error: initializing argument 4 of ‘Customer::Customer(char*, char*, int, char*, float)’|
/home/rej3kt/Desktop/car_class/car project/main.cpp|54|error: invalid conversion from ‘char’ to ‘char*’|
/home/rej3kt/Desktop/car_class/car project/main.cpp|54|error: initializing argument 1 of ‘void Customer::setPcode(char*)’|
||=== Build finished: 4 errors, 0 warnings ===|
Got it working now. Thank's mate you're a life saver. In programming it's always the little mistakes that screw you over. A semi colon here, an extra bracket there etc...
people keep telling me that lol, I'm not going to try confuse myself again. I'll leave it the way i've been taught.
Great, code::blocks has decided to randomly delete my entire project and It's not in my recycle bin either. Think most of it is on these forums anyways lol.
Okay well since code:blocks decided to delete any trace of my program I've managed to piece it back together, I seem to have a clusterfuck of errors though and can't quite see where they're all stemming from. There's something I've not defined I think.
#include <iostream>
#include <string.h>
#include "cust.h"
#include <cstdlib>
#include <fstream>
usingnamespace std;
int main()
{
char cust_name[50];
char cust_gender[50];
int cust_phone;
char cust_pcode[50];
float cust_dob;
int number;
char username[50];
Customer c1(cust_name, cust_gender, cust_phone, cust_pcode, cust_dob);
cout << " Please enter your name to start: "<<endl;
cin.getline(username, 50);
do{
cout << "\n\n\nWelcome, please enter a number to go to that section on the menu:\n1) Enter your car name"<<endl;
cout << "2) Enter your car colour" << endl;
cout << "3) Enter the age of your age"<<endl;
cout << "4) Enter the value of your car in GBP"<<endl;
cout << "5) Enter how many miles per gallon your car does"<<endl;
cout << "6) Save any informaion entered" <<endl;
cout << "7) Retrieve any previously entered information" <<endl;
cout << "8) Exit program"<<endl;
cin >> number;
ofstream myfile;
switch (number){
case 1:
cout << "Enter your car name: " << endl;
cin >> cust_name;
c1.setName(cust_name);
break;
case 2:
cout << "Enter your car colour: " << endl;
cin >> cust_gender;
c1.setGender(cust_gender); break;
case 3:
cout << "Enter the age of your car: " << endl;
cin >> cust_phone;
c1.setPhone(cust_phone); break;
case 4:
cout << "Enter the value of your car in GBP: " << endl;
cin >> cust_pcode;
c1.setPcode(cust_pcode);
break;
case 5:
cout << "Enter how many miles per gallon your car does: " << endl;
cin >> cust_dob;
c1.setDob(cust_dob); break;
case 6:
cout << "Saved!"<<endl;
myfile.open ("class2.txt");
myfile << c1.getName() << endl;
myfile << c1.getGender() << endl;
myfile << c1.getPhone() << endl;
myfile << c1.getPcode() << endl;
myfile << c1.getDob() <<endl;
myfile.close();
break;
case 7:
break;
case 8:
cout << "Press enter to close"<<endl;
break;
return 0;
}
}while(number !=8 );
cout << "\n\n\n\n\n\n\n\n\n" ;
cout << "Your car name is: " << c1.getName() <<endl;
cout << "Your car colour is: " << c1.getGender() <<endl;
cout << "Your car is " << c1.getPhone() << " years old"<<endl;
cout << "Your car is worth £" <<c1.getPcode() <<endl;
cout << "Your car does " <<c1.getDob()<< "mpg"<<endl;
return 0;
}
/home/rej3kt/Desktop/C++ Class/custclass/cust.cpp||In constructor ‘Customer::Customer(char*, char*, int, char*, float)’:|
/home/rej3kt/Desktop/C++ Class/custclass/cust.cpp|9|error: ‘cust_name’ was not declared in this scope|
/home/rej3kt/Desktop/C++ Class/custclass/cust.cpp|10|error: ‘cust_gender’ was not declared in this scope|
/home/rej3kt/Desktop/C++ Class/custclass/cust.cpp|11|error: ‘cust_phone’ was not declared in this scope|
/home/rej3kt/Desktop/C++ Class/custclass/cust.cpp|12|error: ‘cust_pcode’ was not declared in this scope|
/home/rej3kt/Desktop/C++ Class/custclass/cust.cpp|13|error: ‘cust_dob’ was not declared in this scope|
/home/rej3kt/Desktop/C++ Class/custclass/cust.cpp||In member function ‘void Customer::setName(char*)’:|
/home/rej3kt/Desktop/C++ Class/custclass/cust.cpp|20|error: ‘cust_name’ was not declared in this scope|
/home/rej3kt/Desktop/C++ Class/custclass/cust.cpp||In member function ‘char* Customer::getName()’:|
/home/rej3kt/Desktop/C++ Class/custclass/cust.cpp|24|error: ‘cust_name’ was not declared in this scope|
/home/rej3kt/Desktop/C++ Class/custclass/cust.cpp||In member function ‘void Customer::setGender(char*)’:|
/home/rej3kt/Desktop/C++ Class/custclass/cust.cpp|31|error: ‘cust_gender’ was not declared in this scope|
/home/rej3kt/Desktop/C++ Class/custclass/cust.cpp||In member function ‘char* Customer::getGender()’:|
/home/rej3kt/Desktop/C++ Class/custclass/cust.cpp|35|error: ‘cust_gender’ was not declared in this scope|
/home/rej3kt/Desktop/C++ Class/custclass/cust.cpp||In member function ‘void Customer::setPhone(int)’:|
/home/rej3kt/Desktop/C++ Class/custclass/cust.cpp|41|error: ‘cust_phone’ was not declared in this scope|
/home/rej3kt/Desktop/C++ Class/custclass/cust.cpp||In member function ‘int Customer::getPhone()’:|
/home/rej3kt/Desktop/C++ Class/custclass/cust.cpp|45|error: ‘cust_phone’ was not declared in this scope|
/home/rej3kt/Desktop/C++ Class/custclass/cust.cpp|49|error: prototype for ‘void Customer::setPcode(char)’ does not match any in class ‘Customer’|
/home/rej3kt/Desktop/C++ Class/custclass/cust.h|29|error: candidate is: void Customer::setPcode(char*)|
/home/rej3kt/Desktop/C++ Class/custclass/cust.cpp||In member function ‘char* Customer::getPcode()’:|
/home/rej3kt/Desktop/C++ Class/custclass/cust.cpp|55|error: ‘cust_pcode’ was not declared in this scope|
/home/rej3kt/Desktop/C++ Class/custclass/cust.cpp||In member function ‘void Customer::setDob(float)’:|
/home/rej3kt/Desktop/C++ Class/custclass/cust.cpp|60|error: ‘cust_dob’ was not declared in this scope|
/home/rej3kt/Desktop/C++ Class/custclass/cust.cpp||In member function ‘float Customer::getDob()’:|
/home/rej3kt/Desktop/C++ Class/custclass/cust.cpp|64|error: ‘cust_dob’ was not declared in this scope|
||=== Build finished: 16 errors, 0 warnings ===|
I know it's alot of code and I'm really sorry. Thanks for any help.
Learn to understand compiler errors -- the compiler tells you that those variables aren't declared. Just rename Customer::name to Customer::cust_name and etc.
And you are using include guards in a wrong way. A correct code would be