C++ programming problem.

Associate
Joined
28 Jul 2014
Posts
694
Location
Liverpool
beard-programmers-final-two.png
 
Last edited:
Associate
Joined
16 Aug 2010
Posts
1,373
Location
UK
Compiling and working here for me.

I would recommend you put your classes into separate files and include the header for each class you want to use. This is some funky formatting and structure.

Spotted a goto too, definitely don't use that. It's strongly discouraged.

I realise this is probably a first attempt at learning how to do C++ but I would recommend reading around on some best practices :). Defining a class inside a main is eccentric to say the least :p.
 
Last edited:
Associate
OP
Joined
28 Jul 2014
Posts
694
Location
Liverpool
Thanks for the advice, I am still kinda new to C++.

It compiles and runs for me too, its just that I can't seem to figure how to cout litresDispensed and totalCost in the customer receipt.
 
Soldato
Joined
22 Dec 2008
Posts
10,370
Location
England
You need to read through an introductory textbook.

C++ is not a friendly language - learning by hacking something together then asking the internets to debug it for you will lead to neither working software nor the ability to create such.

For example, the int main(); statement here declares the existence of a function called main, which the compiler already knows about because you're writing main() at the time. It doesn't call main. It bears no relation to the new scope created immediately afterwards. The most generous possible interpretation is that you've deliberately written some dead code in the middle of a function.

Code:
int main();
{
  petrolPump obj;
  int fuelType;
  // more stuff cut out here
 
Associate
Joined
16 Aug 2010
Posts
1,373
Location
UK
If you want to learn C++, I'd learn C first, before getting into objects and the standard library as well. Just to understand some basics, e.g. pointers, memory.
 
Back
Top Bottom