Trouble with Classes

Trying to get ahead this summer with C++ and I ran into some problems when writing a simple class program. Here are the two files in my project

Training 5.ccp
#include <iostream>
#include <stdlib.h>
#include "Training5.h"
using namespace std;

int main(int argc, char *argv[])
{
Pop Pepsi;
Pepsi.Name = Pepsi;
Pepsi.SodaColor = brown;
Pepsi.Can = blue;
Pepsi.pop = caramel;
Pepsi.size = 12;
Pepsi.company = Pepsi Co;
Pepsi.ammt_left = 100;


system("PAUSE");
return 0;
}

Training5.h
#include <string>
enum color {orange, brown, clear, red, blue, green};
enum flavor {oj, caramel, lemon lime, cherry};

Class Pop{
Public:
string Name;
color SodaColor;
color Can;
flavor pop;
int size;
string company;
int ammt_left;

int drink(int gulps){
if( ammt_left > 0){
ammt_left = ammt_left - (gulps * 2)}
return ammt_left;
}
int spill(){
ammt_left = 0
return ammt_left;
}

};

And here are my compiler errors:


Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\Makefile.win"
Executing make...
make.exe -f "C:\Dev-Cpp\Makefile.win" all
C:\Dev-Cpp\Makefile.win:27: warning: overriding commands for target `"Training'
C:\Dev-Cpp\Makefile.win:24: warning: ignoring old commands for target `"Training'

make.exe: Circular "Training <- "Training dependency dropped.

g++.exe -c "Training 5.cpp" -o "Training 5.o" -I"C:/Dev-Cpp/include" -I"C:/Dev-Cpp/include/c++" -I"C:/Dev-Cpp/include"

In file included from Training 5.cpp:3:
Training5.h:3: parse error before `,' token
Training5.h:5: parse error before `{' token
Training5.h:10: storage size of `pop' isn't known
Training5.h:10: storage size of `pop' isn't known
Training5.h:12: 'string' is used as a type, but is not defined as a type.

Training5.h: In function `int drink(int)':
Training5.h:17: parse error before `}' token
Training5.h: In function `int spill()':
Training5.h:22: parse error before `return'

Training 5.cpp: In function `int main(int, char**)':
Training 5.cpp:8: `Pop' undeclared (first use this function)
Training 5.cpp:8: (Each undeclared identifier is reported only once for each
function it appears in.)

Training 5.cpp:8: parse error before `;' token

Training 5.cpp:9: `Pepsi' undeclared (first use this function)

Training 5.cpp:14: parse error before `;' token

make.exe: *** [5.o"] Error 1

Execution terminated


I have basic knowledge of Java up to classes and filewriting, just trying to get a head start on C++, any help would be much appreciated.
In your flavor enum, you have a space in lemon lime:
enum flavor {oj, caramel, lemon lime, cherry};

Try lemon_lime:
enum flavor {oj, caramel, lemon_lime, cherry};

I should have tried compiling it before I responded, but there is a few more errors. In you Pop class, Class and Public need to be lowercase.

These lines:
1
2
3
         ammt_left = ammt_left - (gulps * 2)
//...
      ammt_left = 0

Need semicolons at the end

And I'm going to try to fix the other errors quickly.

Edit: This line:
Pepsi.Name = Pepsi;

You're trying to assign Pepsi's name a string. String's need to have double quotes. Try:
Pepsi.Name = "Pepsi";

Same here:
Pepsi.company = Pepsi Co;

Try:
Pepsi.company = "Pepsi Co";
Last edited on
enum flavor {oj, caramel, lemon lime, cherry};

Is lemon lime one enum, or two? :) You have other cases where you've spread into two separate tokens.

The keyword class has a lower case c. Likewise public.

You've got a lot of lines missing the terminating semi-colon.

If you want to directly assign a string, you need ".

e.g. Pepsi.Name = "Pepsi";

Edit: OMG NINJAAAAA!
Last edited on
<3 Moschops
Thanks, I shoulda known better than most of those errors, I'm making C++ more foreign than it needs to be. I'll fix those errors and see if there are other errors.
For reference, all keywords in C++ are lower-case.
These errors are left. Would it be possible to explain what these errors are saying in somewhat simpler terms, just so I know what htey are in the future, specifically the ones bolded:


C:\Dev-Cpp\Makefile.win:27: warning: overriding commands for target `"Training'
C:\Dev-Cpp\Makefile.win:24: warning: ignoring old commands for target `"Training'

make.exe: Circular "Training <- "Training dependency dropped.

g++.exe -c "Training 5.cpp" -o "Training 5.o" -I"C:/Dev-Cpp/include" -I"C:/Dev-Cpp/include/c++" -I"C:/Dev-Cpp/include"

In file included from Training 5.cpp:3:
Training5.h:7: 'string' is used as a type, but is not defined as a type.

Training5.h:12: 'string' is used as a type, but is not defined as a type
The top two in bold aren't issues with your code; they're issues with your IDE.

The lower error looks like some kid of namespace/multi-declaration issue. Since you're not using namespaces in your header file, I'm not surprised the compiler doesn't know what to do with string in there, but to be honest I think your best bet is to get an IDE that comes with a compiler made in the last 15 years (C++ has come a long way since Dev-Cpp was last updated (including actually being standarised), assuming you're using Bloodshed Dev-Cpp).
Huh, well that's nice, any suggestions?
sweet action, after trying out a few of those I ended up with the orwell Dev-cpp, everything is making a lot more sense, thank you.
Topic archived. No new replies allowed.