reading data into a console from a file

Hello all I'm new to this forum, and I have been trying to get my coding to allow me to read the saved data from a file into the console window, and it doesn't seem to be working. Any advice on what I should add to this existing coding so I can read the saved info...Thanks in advance for all your advice...

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <stdio.h>
#include <windows.h>
using std::ios;
using std::ofstream;
using std::ifstream;
using namespace std;

int main()
{ 
SetConsoleTitle(("Money Tracker V 2.1"));
int menuchoice=0;
float bal=0.0;
float secondbankbal=0.0;
float income=0.0;
float rent=0.0;
float insurance=0.0;
float cellphone=0.0;
float net=0.0;
float gas=0.0;
float ui=0.0;
float creditcard=0.0;
float creditcard2=0.0;
float firsttally=0.0;
float sectally=0.0;
float thitally=0.0;
float frthtally=0.0;
float fifthtally=0.0;
float sixthtally=0.0;
float billtotal=0.0;
float leftovertally=0.0;
float newtally=0.0;
float seventhtally=0.0;
float eigthtally=0.0;
string date=" ";
ofstream savings;

cout<<endl;
cout<<endl;
cout<<"   $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"<<endl;
cout<<"   $                 Joe Votto's Money Budgeting Program Version 2.0         $"<<endl; 
cout<<"   $                        Created On October 23rd 2010                     $"<<endl;
cout<<"   $             Will Calculate Left Over Money After Bills Are Input        $"<<endl;
cout<<"   $                           Then Save It To A File                        $"<<endl;                                                         
cout<<"   $                                 USER MENU                               $"<<endl;
                             
cout<<"   $                       Select Option 2 To Add To Report                  $"<<endl;
cout<<"   $                       Select Option 3 To Exit Program                   $"<<endl;
cout<<"   $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"<<endl;
cout<<endl;
cout<<"                            Please Select Menu Choice: "; 
cin>>menuchoice;

if (menuchoice==1)
{
ifstream.savings ("C:/Users/primo/Documents/Dough/savings.txt", ios::in);
while (!savings.eof())
{
    getline(savings,finaltotal);
	cout<<finaltotal<<endl;
}
savings.close();
	if (menuchoice==2)
{
savings.open ("C:/Users/primo/Documents/Dough/savings.txt", ios::app);

cout<<"Enter Date: ";
cin>>date;
savings<<"The Date Is: "<<date<<endl;
cout<<"Enter Bank Balance: ";
cin>>bal;
savings<<"Bank Balance: "<<bal<<endl;
cout<<"Enter Second Bank Balance: ";
cin>>secondbankbal;
savings<<"Second Bank Balance:"<<secondbankbal<<endl;
cout<<"Enter Expected Income Amount: ";
cin>>income;
savings<<"Income "<<income<<endl;
firsttally=income+secondbankbal+bal;
savings<<"Total Amount Of Income "<<firsttally<<endl;
cout<<"Income Total Is: "<<firsttally<<endl;
cout<<"Enter Rent Amount: ";
cin>>rent;
savings<<"Rent Is "<<rent<<endl;
sectally=firsttally-rent;
savings<<"Total To This Point Is "<<sectally<<endl;
cout<<"Total So Far Is: "<<sectally<<endl;
cout<<"Enter Cable, Internet, and Phone Amount: ";
cin>>net;
savings<<"Internet/Cable/Phone Amount Is "<<net<<endl;
thitally=sectally-net;
savings<<"Total To This Point is: "<<thitally<<endl;
cout<<"Total So Far Is: "<<thitally<<endl;
cout<<"Enter Cell Phone Amount: ";
cin>>cellphone;
savings<<"Cell Phone Amount:"<<cellphone<<endl;
frthtally=thitally-cellphone;
savings<<"Total At This Point Is "<<frthtally<<endl;
cout<<"Total So Far Is: "<<frthtally<<endl;
cout<<"Enter Gas Bill Amount ";
cin>>gas;
savings<<"Gas Amount is: "<<gas<<endl;
fifthtally=frthtally-gas;
savings<<"Total At This Point Is "<<fifthtally<<endl;
cout<<"Total So Far Is: "<<fifthtally<<endl;
cout<<"Enter Electric Bill Amount ";
cin>>ui;
savings<<"UI Amount Is: "<<ui<<endl;
sixthtally=fifthtally-ui;
savings<<"Total To This Point Is: "<<sixthtally<<endl;
cout<<"Total So Far Is: "<<sixthtally<<endl;
cout<<"Enter Credit Card Bill Amount: ";
cin>>creditcard;
savings<<"Credit Card Amount Is: "<<creditcard<<endl;
seventhtally=sixthtally-creditcard;
savings<<"Total To This Point Is: "<<seventhtally<<endl;
cout<<"Total So Far Is: "<<seventhtally<<endl;
cout<<"Enter Auto Insurance Amount: ";
cin>>insurance;
savings<<"Auto Insurance Amount Is: "<<insurance<<endl;
eigthtally=seventhtally-insurance;
savings<<"Total To This Point Is: "<<eigthtally<<endl;
cout<<"Final Total Is: "<<eigthtally<<endl;
billtotal=firsttally-eigthtally;
savings<<"Final Total Is: "<<billtotal<<endl;
leftovertally=firsttally-billtotal;
savings<<"Money Left Over Is: "<<leftovertally<<endl;
cout<<"Total Amount Deducted From Income Is: "<<billtotal<<endl;
savings<<"Total Amount Deducted Is: "<<billtotal<<endl;
cout<<"Thank You For Using My Money Budgeting Program, Created In C++ Language"<<endl;
savings<<endl;
savings<<endl;
savings<<endl;
savings.eof();
savings.close();
system ("PAUSE");
}
if (menuchoice==3)
system ("PAUSE");
return 0;
}
} 
Have you stepped thru your code in a debugger?

I would think that:
1
2
3
4
5
6
7
8
9
10
11
float firsttally=0.0;
float sectally=0.0;
float thitally=0.0;
float frthtally=0.0;
float fifthtally=0.0;
float sixthtally=0.0;
float billtotal=0.0;
float leftovertally=0.0;
float newtally=0.0;
float seventhtally=0.0;
float eigthtally=0.0;
ought to be an array.

In fact, a lot of that stuff should be pulled into a struct don't you think?
Topic archived. No new replies allowed.