The program save some funny thing

This is a discussion on The program save some funny thing within the C++ Programming forums, part of the General Programming Boards category; After deposit, the program will save the changes of balance, but the saved thing is some funny thing. How to ...

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    7

    The program save some funny thing

    After deposit, the program will save the changes of balance, but the saved thing is some funny thing. How to solve the problem?

    The funny thing that display on screen:
    $4.25248e-311

    Code:
    case 'D':
    			acctType=men.typeMenu();
    			if(acctType=='C')
    			{
    				int acNo,found=0,i;
    				double bal1,bal2;
    				system("cls");
    				r.open("checking.txt");
    				cout<<"\nDeposit into checking account";
    				cout<<"\nEnter your checking account number: ";
    				cin>>acNo;
    				i=-1;
    				while(!r.eof())
    				{
    					i=i+1;
    					r.read((char*)(&che[i]),sizeof(che[i]));
    					if(acNo==che[i].getacctNum())
    					{	
    						bal1=che[i].getBal();
    						che[i].deposit();
    						bal2=che[i].getBal();
    						tra[n].setTran(acNo,d,m,y,h,t,"Checking","Deposit","Success",bal1,bal2);
    						w.open("transaction.txt",ios::app,ios::ate);
    						w.write((char*)(&tra[n]),sizeof(tra[n]));
    						w.close();
    						found=1;
    					}
    				}
    				r.close();
    				w.open("checking.txt");
    				for(int c=0;c<i;c=c+1)
    					w.write((char*)(&che[c]),sizeof(che[c]));
    				w.close();
    				if(found==0)
    				{
    					cout<<"\nSorry, no such account.";
    				}
    				cout<<"\n\nPress ENTER to continue...";
    				while(!cin.get()){};
    				while(!cin.get()){};				
    				break;
    			}
    			if(acctType=='S')
    			{
    				int acNo,found=0,i;
    				double bal1,bal2;
    				system("cls");
    				r.open("saving.txt");
    				cout<<"\nDeposit into saving account";
    				cout<<"\nEnter your saving account number: ";
    				cin>>acNo;
    				i=-1;
    				while(!r.eof())
    				{
    					i=i+1;
    					r.read((char*)(&sav[i]),sizeof(sav[i]));
    					if(acNo==sav[i].getacctNum())
    					{	
    						bal1=sav[i].getBal();
    						sav[i].deposit();
    						bal2=sav[i].getBal();
    						tra[n].setTran(acNo,d,m,y,h,t,"Saving","Deposit","Success",bal1,bal2);
    						w.open("transaction.txt",ios::app,ios::ate);
    						w.write((char*)(&tra[n]),sizeof(tra[n]));
    						w.close();
    						found=1;
    					}
    				}
    				r.close();
    				w.open("saving.txt");
    				for(int c=0;c<i;c=c+1)
    					w.write((char*)(&sav[c]),sizeof(sav[c]));
    				w.close();
    				if(found==0)
    				{
    					cout<<"\nSorry, no such account.";
    				}
    				cout<<"\n\nPress ENTER to continue...";
    				while(!cin.get()){};
    				while(!cin.get()){};				
    				break;
    			}
    			else
    			{
    				cout<<"Invalid type";
    				cout<<"\n\nPress ENTER to continue...";
    				while(!cin.get()){};
    				while(!cin.get()){};
    			}
    			break;

  2. #2
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    you need to set your output flags before any cout is made. I cant remember them exactly as i have not had to use them in a while, and my older c++ programs r missing...

    Code:
    #include <math>
    Code:
    cout << setiosflags << ios::setprecision(2) << ios::right;
    (think im missing one)

  3. #3
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,156
    and change your tabs to 4 spaces so your code doesn't horizontally scroll 2 screens
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  4. #4
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    similar to what RoD said:
    Code:
    #include <iomanip>
    
    ...
    
    std::cout<<setiosflags(ios::fixed|ios::showpoint|ios::right)<<setprecision(2);
    fixed: forces teh decimal
    showpoint: shows trailing zeroes
    right: right aligns (so the decimals line up)
    setprecision: number of decimal points to round to
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Low level program to save a mjpeg stream
    By Rufe0 in forum Linux Programming
    Replies: 6
    Last Post: 09-22-2009, 05:53 AM
  2. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  3. insufficient memory for tsr
    By manmohan in forum C Programming
    Replies: 8
    Last Post: 01-02-2004, 08:48 AM
  4. Date program starts DOS's date
    By jrahhali in forum C++ Programming
    Replies: 1
    Last Post: 11-24-2003, 04:23 PM
  5. most challenging thing to program
    By volk in forum A Brief History of Cprogramming.com
    Replies: 52
    Last Post: 03-28-2003, 02:56 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21