Connecting Tech Pros Worldwide Help | Site Map

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

Newbie
 
Join Date: Oct 2009
Location: perak
Posts: 1
#1: Oct 16 '09
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
Expert
 
Join Date: Mar 2008
Location: Naperville, Illinois U.S.
Posts: 828
#2: Oct 16 '09

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


Quote:

Originally Posted by sailormoon View Post

when i run this program, data from data.txt cannot out...
thi give some error...
i dont know how to solve

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.
Needs Regular Fix
 
Join Date: Jul 2008
Posts: 380
#3: Oct 16 '09

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


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.
Reply