int main()
{
Lunar l();
char difficulty;
float ffrate;
float t = 0;
difficulty = menu();
system("clr");
l.setdifficulty(difficulty);
.
.
.
}
This is what I have so far.
For some reason, I get this error saying:
"left of '.setdifficulty' must have class/struct/union type"
I declared Lunar l but compiler doesn't seem to know it. What's the problem?
private:
//ATTRIBUTES
int ffr; //fuel flow rate
float vs; //vertical speed
float alt; //altitiude
int fuel; //amount of fuel
int mass; //mass of the lander itself
int fcr; //fuel consumption rate
int thrust; //maximum thrust of the engine
};
///////////////////////////////////////////////////////////////////////
//Implementation File
#include <iostream>
#include "class.h"
using namespace std;
Lunar::Lunar()
{
ffr = 0;
vs = 0;
alt = 1000;
fuel = 1700;
mass = 900;
fcr = 10;
thrust = 5000;
}
void Lunar::setdifficulty(char difficulty)
{
switch (difficulty)
{
case 'E': case 'e':
fuel = 2000;
break;
int main()
{
Lunar l();
char difficulty;
float ffrate;
float t = 0;
difficulty = menu();
system("clr");
l.setdifficulty(difficulty);
while ((l.getfuel() != 0) && (l.getalt() != 0))
{
status();
cout << "Enter fuel flow rate: ";
cin >> ffrate;
for (int i = 1; i <= 2000; ++i)
{
l.changetime (i, t);
t = l.gettime(t);
l.changevelo (t);
l.changealt (t);
}
}
if ((l.getalt () == 0) && (l.getvelo () >= (-3) && l.getvelo () <= 0))
{
cout << "\n" << "Great landing. You are in one piece" << endl;
system ("pause");
}
if ((l.getalt () == 0) && (l.getvelo () <= (-3)))
{
cout << "\n" << "You are torn apart." << endl;
system ("pause");
}
if ((l.getalt () > 0) && (l.getvelo () >= 0) && (l.getfuel() == 0))
{
cout << "\n" << "You are orbit around the moon rest of your life" << endl;
system ("pause");
}
These are my project.
I haven't done any error handling so there should be many minor errors.
The major problem is that I do get these errors:
error C2228: left of '.setdifficulty' must have class/struct/union type
error C2228: left of '.getfuel' must have class/struct/union type
error C2228: left of '.getalt' must have class/struct/union type
fatal error C1903: unable to recover from previous error(s); stopping compilation
I declared "Lunar l" at the beginning of function main.
Oh, and this is the first time I created a class.
It should look disgusting to many programmers...:)
Not easy to spot but this is the problem line (the first line in the main function): Lunar l(); //Error in declaring a variable of class Lunar using default constructor
As written, that is actually a prototype for a function that takes no parameters and returns a variable of type Lunar.