C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 12th, 2006, 01:18 PM
saifo saifo is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2005
Posts: 6 saifo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 31 m 8 sec
Reputation Power: 0
Can anyone help me with this

hi how r u?
i try to open file but i cant open it and compute.
could u please help me?

#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

int main()
{
int type;
int account;
double balance;
double amount;
double y,n,x;
{
ofstream myfile;
myfile.open("saif.txt");

cout<<"Enter account number , balance , Type , Amount"<<endl;
cout<<"Enter end-of-file to end file"<<endl;
myfile.close();
while(cin>>account>>balance>>type>>amount)
{
myfile<<account<<" "<<balance<<" "<<type<<" "<<amount<<endl;
}
}
{
ifstream myfile ("saif.txt");
if (myfile.is_open())
{
while (! myfile.eof() )
{
ifstream myfile ("saif.txt");
if (myfile.is_open())
{
while (! myfile.eof() )
{
cin>>account>>balance>>type>>amount;
}
myfile.close();
}

else cout << "Unable to open file";
}
myfile.close();
}

else cout << "Unable to open file";






if (type==0)
y=balance-amount;
if (type==1)
y=balance+amount;
if(type==2)
y=amount/2;
cout<<amount<<" "<<setprecision(2)<<fixed<<y<<endl;
if(y>1000)
{
x=y*.01;
n=x+y;
cout<<"This acouut has 1% to the balance and became : "<<n<<endl;
}
if(y<0)
{
cout<<setprecision(2)<<fixed<<y<<"Warning Balance is negative you will go to jill"<<endl;
}
}

return 0;
}

Reply With Quote
  #2  
Old March 12th, 2006, 03:34 PM
Cirus Cirus is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 276 Cirus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 48 m 58 sec
Reputation Power: 4
Quote:
Originally Posted by saifo
[COLOR=Red]hi how r u?

o very well !!!


Quote:
i try to open file but i cant open it and compute.
could u please help me?

sure

You are getting error because in between you are closing your file
(see your code myfile.close) and then continuing with input operationn. then at the end you are checking through if-lause whether your file is open or not.Answer is not open due to above stated reason.

Reply With Quote
  #3  
Old March 12th, 2006, 05:10 PM
saifo saifo is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2005
Posts: 6 saifo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 31 m 8 sec
Reputation Power: 0
Quote:
Originally Posted by Cirus
sure

You are getting error because in between you are closing your file
(see your code myfile.close) and then continuing with input operationn. then at the end you are checking through if-lause whether your file is open or not.Answer is not open due to above stated reason.


thanks cirus

i removed myfile.close but not open
try in your computer and tell what is the erorr
ok

Reply With Quote
  #4  
Old March 13th, 2006, 12:00 AM
Cirus Cirus is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 276 Cirus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 48 m 58 sec
Reputation Power: 4
Can you indent your code please I am suspecting error of braces.The essence is that at some point the file is still open.That is why you are not being able to open it.

Reply With Quote
  #5  
Old March 13th, 2006, 12:07 AM
Cirus Cirus is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 276 Cirus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 48 m 58 sec
Reputation Power: 4
Quote:
Originally Posted by saifo
ifstream myfile ("saif.txt");

After this step you have not opened myfile for input.Hence all operations will be igneored. Ignore my previous reply where I asked you to remove myfile.close(). I thought that you were using fstream.h

After this line , open your myfile by
Code:
mfile.open("saif.txt")


Quote:
if (myfile.is_open())
{
while (! myfile.eof() )
{
ifstream myfile ("saif.txt");

//Why this step when you have already created an ifstream object.???????

Quote:
if (myfile.is_open())
{
while (! myfile.eof() )
{
cin>>account>>balance>>type>>amount;
}
myfile.close();
}

else cout << "Unable to open file";
}
myfile.close();
}

else cout << "Unable to open file";


First open your file after declaring it as an ifstream object. the line if (myfile.is_open()) will give you FALSE as answer and hence else clause will get executed.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Can anyone help me with this


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT