so this class that i wrote, won't allow me to call it, every time i try to make an instance of it, it tells me that the instance name need a semicolon before it.
now i made a test class to see on a smaller scale what i was doing wrong, but my test class works perfectly, and i don't see any diference.
there is my test class
Code:
class cls
{
public:
void seti(string i);
string geti();
private:
string i;
};
void cls::seti(string i)
{
this -> i = i;
}
string cls::geti()
{
return i;
}
and when i call it, i call it like this
Code:
cls a;
cout << "enter a word: ";
cin >> word;
a.seti(word);
it works just fine.
but in my actual program, that i need it to work in, i get the error. this is the class and its functions.
Code:
class info
{
public:
info(char initname[101], float initcalories, float initcarbohydrates, float initfat, float initcholesterol, float initsodium, float initprotein);
~info();
void setname(char name[101]);
void setcalories(float calories);
void setcarbohydrates(float carbohydrates);
void setfat(float fat);
void setcholesterol(float cholesterol);
void setsodium(float sodium);
void setprotein(float protein);
char getname();
float getcalories();
float getcarbohydrates();
float getfat();
float getcholesterol();
float getsodium();
float getprotein();
private:
char name[101]; // name of the food
float calories; // calories
float carbohydrates;// grams
float fat; // grams
float cholesterol; // grams
float sodium; // grams
float protein; // grams
};
void info::setname(char name[101]) { this -> name[101] = name[101]; }
void info::setcalories(float calories) { this -> calories = calories; }
void info::setcarbohydrates(float carbohydrates){ this -> carbohydrates = carbohydrates; }
void info::setfat(float fat) { this -> fat = fat; }
void info::setcholesterol(float cholesterol) { this -> cholesterol = cholesterol; }
void info::setsodium(float sodium) { this -> sodium = sodium; }
void info::setprotein(float protein) { this -> protein = protein; }
char info::getname() { return name[101]; }
float info::getcalories() { return calories; }
float info::getcarbohydrates() { return carbohydrates; }
float info::getfat() { return fat; }
float info::getcholesterol() { return cholesterol; }
float info::getsodium() { return sodium; }
float info::getprotein() { return protein; }
and when i call it, it looks like this
Code:
static char tempName[101];
static float tempCalories;
static float tempCarbohydrates;
static float tempFat;
static float tempCholesterol;
static float tempSodium;
static float tempProtein;
cout << "name:\t\t\t> ";
cin.get(tempName[101]);
cin.ignore(100, '\n');
cout << "\ncalories:\t\t> ";
tempCalories = getfloat();
cout << "\ncarbohydrates:\t\t> ";
tempCarbohydrates = getfloat();
cout << "\nfat:\t\t\t> ";
tempFat = getfloat();
cout << "\ncholesterol:\t\t> ";
tempCholesterol = getfloat();
cout << "\nsodium:\t\t\t> ";
tempSodium = getfloat();
cout << "\nprotein:\t\t> ";
tempProtein = getfloat();
info alpha(tempName[101],tempCalories,tempCarbohydrates,tempFat,tempCholesterol,tempSodium,tempProtein);
i know that i don't need all of those get and set functions, but they are there for a diferent part of hte code, and when i comment them out, it still won't work.
these are hte 3 syntax errors that i'm getting
error C2146: syntax error : missing ';' before identifier 'alpha'
warning C4551: function call missing argument list
error C3861: 'alpha': identifier not found, even with argument-dependent lookup
i've gotta be missing something obvious. i really apreciate your help
oh yeah, i'm using iostream, conio, iomanip, and ctype. and getfloat() only checks for good input, returns 0 if it is bad input, and makes it so that my program doesn't die when i have bad input.
i've run it in both devC++ and visual studio.net
edit: the functions taht let me manipulate the private variables in my class are formatted nicely in the IDE's, they just coppied over wierd, sorry if its harder to read. i'll try to fix it.