By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,649 Members | 1,816 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,649 IT Pros & Developers. It's quick & easy.

i dont know what wrong with program..please help me

P: 1
this information i put in data.txt
11221 MOHD IRFAN 80 70
11222 NURUL FITRAH 80 90
11223 MOHD FARHAN 70 80
11224 WAFFIN WARDAH 80 60
11225 SYAMSUL 50 50
99999 TAMAT 0 0

Expand|Select|Wrap|Line Numbers
  1. #include<fstream.h>
  2. #include<iostream.h>
  3. #include<stdlib.h>
  4.  
  5. main()
  6. {
  7. char nama[20];
  8. double matrik;
  9. int markah1,markah2;
  10. char gred;
  11. ifstream Fail_input("data.txt");
  12.  
  13. if (Fail_input==NULL)
  14. {
  15. cout<<"Tidak dapat dibuka untuk output";
  16. exit(1);
  17. }
  18.  
  19. cout<<" No Matrik "<<"Nama "<<" Gred "<<endl;
  20.  
  21. do
  22. {
  23. Fail_input>>matrik>>nama>>gred;
  24.  
  25. if ((markah1 + markah2)/2>90)
  26. gred='A';
  27. else if ((markah1+markah2)/2>70)
  28. gred='B';
  29. else if((markah1+ markah2)/2>50)
  30. gred='C';
  31. else gred='F';
  32.  
  33. Fail_input>>matrik>>nama>>markah1>>markah2;
  34.  
  35.  
  36. }while (matrik !=99999) ;
  37.  
when i run this program, data from data.txt cannot out...
thi give some error...
i dont know how to solve
Oct 16 '09 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 2,391
@sailormoon
You will get better assistance if you make it easier to help you.
What error did you get?
Did the error occur when you compiled your program or when you ran it?
If your program produced the wrong output, then please describe the output you got and how it differs from what you expected.

By the way, your source code is easier to read if you enclose it in CODE tags by highlighting the source code and then pressing the "#" button at the top of the Message window.
Oct 16 '09 #2

100+
P: 687
You don't print anything - you only read data from file. Then note that string input will be read until the first whitespace - so your names will be read only in half, and then the number will be expected.
Oct 16 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.