Please help me - void functions/byref
Hello. I need some help with homework. I'm not asking anyone to do it for me, but I need some help.
Basically, I have to create a program with a main function that will call two other functions. The two other functions will be inputFunction and outputFunction. The inputFunction will pull the data from a text file that I've made. The outputFunction will calculate the totals for each category and the averages for each category. I am not allowed to use an array for this.
my notepad data looks as follows:
"Day Food Clothing School Entertainment
Monday 10 20 30 40
Tuesday 15 21 25 31
Wednesday 16 22 26 32
Thursday 17 23 27 33
Friday 18 24 28 34
Saturday 19 14 11 13
Sunday 4 8 9 10"
The code I've written so far (which seems to be useless) is as follows:
Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void inputFunction(ifstream& infile);
int main()
{
inputFunction(infile);
}
void inputFunction(ifstream& infile)
{
ifstream infile;
infile.open("expenses.txt");
string day1, day2, day3, day4, day5, day6, day7, day, food, clothing, school, entertainment;
double food1, food2, food3, food4, food5, food6, food7;
double clothing1, clothing2, clothing3, clothing4, clothing5, clothing6, clothing7;
double school1, school2, school3, school4, school5, school6, school7;
double ent1, ent2, ent3, ent4, ent5, ent6, ent7;
double totalFood, double totalClothing, double totalSchool, double totalEnt;
double averageFood, double averageClothing, double averageSchool, double averageEnt;
ifstream infile;
infile >> day >> " " >> food >> " " >> clothing >> " " >> school >> " " >> entertainment;
cout << " " << endl;
infile >> day1 >> " " >> food1 >> " " >> clothing1 >> " " >> school1 >> " " >> ent1;
cout << " " << endl;
infile >> day2 >> " " >> food2 >> " " >> clothing2 >> " " >> school2 >> " " >> ent2;
cout << " " << endl;
infile >> day3 >> " " >> food3 >> " " >> clothing3 >> " " >> school3 >> " " >> ent3;
cout << " " << endl;
infile >> day4 >> " " >> food4 >> " " >> clothing4 >> " " >> school4 >> " " >> ent4;
cout << " " << endl;
infile >> day5 >> " " >> food5 >> " " >> clothing5 >> " " >> school5 >> " " >> ent5;
cout << " " << endl;
infile >> day6 >> " " >> food6 >> " " >> clothing6 >> " " >> school6 >> " " >> ent6;
cout << " " << endl;
infile >> day7 >> " " >> food7 >> " " >> clothing7 >> " " >> school7 >> " " >> ent7;
cout << " " << endl;
}
I know it's ugly looking and I apologize for that. I'm getting errors. I don't know what I'm doing and I'm on the verge of switching my major. I'm so frustrated right now. Can someone please help me along the way? I'd appreciate it more than you know.