Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Understanding logic for final

$
0
0
Hey there codies, I need help getting something to work, and or understand why and the heck I'm getting the output i'm getting. I'm supposed to write a C++ program that reads a "checkbook register" file one line at a time and
calculates the balance by adding all of the deposits and subtracting all of the check amounts.

I'm able to get the file to read (checkbook.txt) but the alignment is off, and its showing some weird numbers. Here's my code so far:

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <sstream>
using namespace std;

string FileName;
void starline();


void starline() //function declarator
{
	for(int j=0; j<65; j++) //function body
		cout << '-';
	cout << endl;
}


int main()
{
	cout << "Enter a file name (including extension): " << endl;
	char Checkbook[1000];
	cin.getline (Checkbook,1000);
	ifstream input(Checkbook);

	if (!input.good())
	{
		cerr << "Unable to open file" << endl;
		exit(1);
	}
	starline();
	while (!input.eof())
	{

		char    deposit[15];
		input.getline(deposit, 15, ':');
		cout << left << setw(15) << deposit;

		char    date[15];
		input.getline(date, 15, ':');
		cout << setw(15) << date;

		char    place[15];
		input.getline(place, 15, ':');
		cout << setw(15) << place;

		char money[15];
		input.getline(money,15);
		cout << right  << setw(15) << '$ ' << money << right << endl;


	}

	starline();


	return 0;
}




checkbook.txt

deposit:July 7:-:300
416:July 8:Albertsons:15.85
417:7/9:Checker Auto:19.95
418:7/10:Super Target:47.50
419:Dec 5:Home Depot:47.89




my output looks like this:
Output

I still don't know how to get it to add the line items where it sees deposit and subtract when it sees a check number. Any help would be appreciated. Not looking for someone to write it for me, but to point me in the right direction

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>