File Problems (Really Nooby Problem)

Okay so Im trying to learn how to write to a txt file and read it. I am still new to programming so I am a big noob :) However, I have come across a problem with my set out. Is there any other errors aswell?

Cash Register.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Cash Register.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include "Cash Register.h"
using namespace std;

int main()
{
	cin >> Balance;
	EndBalance();
	return 0;
}

// Open Balance function
void StartBalance()
{
   // Aint done this yet
}

// Save Balance function
void EndBalance()
{
  EndBalance.open ("EndBalance.txt"); // EndBalance is not recognized either
  EndBalance << Balance; // balance is not recognized
  EndBalance.close();
};


Cash Register.h
1
2
3
4
5
6
7
#pragma once

class CashRegister
{
	ofstream EndBalance;
	int Balance;
}
Last edited on
I really think you should learn to use functions before you try to learn how to use a class. You have never declared a variable named Balance, in either main() or EndBalance(). If you're intending to use your class you've never declared an instance of that class either.
But i declared it in the .h file. Does that not work?
The two member variables of your class (EndBalance and Balance) only exist when there is a CashRegister instance (object) to go along with them. I would suggest reading the site's tutorial, where it makes an instance of a Rectangle class, with a length and width property.

I would also not name a function that same as a potential variable.
Last edited on
Okay thanks I will change the names of the functions. I will come back to this project once I am a bit more experienced I think
Topic archived. No new replies allowed.