Program I'm writing

Can someone look through this and tell me why amount isn't displaying anything in the "Total" file? I can't figure it out. Trying to refresh myself on C++ right now, so my brain isn't functioning correctly. Also why it's not displaying anything when I add in a cout statement.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;

int main()
{
string amount = "";
string minus = "";
double amount1 = 0.00;
double amount2 = 0.00;
double amount3 = 0.00;
double amount4 = 0.00;
double amount5 = 0.00;
double amount6 = 0.00;
string temp = "";
int comma = 0;
int electronicsRow = 0;
int clothesRow = 0;
int carRow = 0;
int foodRow = 0;
int paymentRow = 0;
int booksRow = 0;
string electronics[15][4] = {"0.0"};
string clothes[15][4] = {"0.0"};
string car[15][4] = {"0.0"};
string food[15][4] = {"0.0"};
string payment[15][4] = {"0.0"};
string books[15][4] = {"0.0"};
string supplies = "";
string type = "";

ifstream inExpenses;
inExpenses.open("Accounting2.txt");
if (inExpenses.is_open())
{
getline(inExpenses, temp, '\n');
temp.erase(0);
getline(inExpenses, supplies, '\n');
while (inExpenses.eof() == false)
{
comma = supplies.find(",", 0);
type = supplies.substr(0, comma);
if (type == "Electronics" || "electronics")
{
supplies.erase(0, comma + 1);
comma = supplies.find(",", 0);
minus = supplies.find("-", 0);
amount += supplies;
}
type.erase(0);
}
ofstream outExpenses;
outExpenses.open("Total.txt");
if (outExpenses.is_open())
{
outExpenses << "Total money spent $" << amount << endl;
outExpenses << amount << endl;
}
outExpenses.close();
inExpenses.close();
}
}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
		while(inExpenses.eof() == false) {
			comma = supplies.find(",", 0);
			type = supplies.substr(0, comma);
			if(type == "Electronics" || "electronics") {
				supplies.erase(0, comma + 1);
				comma = supplies.find(",", 0);
				minus = supplies.find("-", 0);
				amount += supplies;
			}
			type.erase(0);
		}
¿does your program terminate?
if yes, you never enter that loop and so `supplies' remains an empty string (¿why the hell is it a string?)
if no, then you never write to the file.

comment your code and show your input file structure.
I should clarify, it does show something, but only "Total money spent". And not the amount underneath like I want it to. It's a string because I never learned a better way of reading data from a text file and using that. What I originally posted is my entire code aside from the Accounting2.txt file, one line of which is Electronics,-22.26,2017,11
Last edited on
Topic archived. No new replies allowed.