![]() | Register | FAQ | Members | Social Groups | User Map | Calendar | Search | Today's Posts | Mark Forums Read |
| | | LinkBack | Thread Tools | Search Thread | Language |
| Sponsored Links |
| | #1 |
![]() Join Date: Apr 2008
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Rep Power: 0 | I'm trying to revise my "knowledge" in C++ and program probably worked is doing something stupid. Program should read from file First name then last name and finally mark that person got, then move to another person and so on. Next step program asks user to enter his score and compare this score with scores which read from file (Mark < Score) and display and write to file everyone who got higher mark than user. Instead of that program writes to file details of first person from file either she got higher score than user or not (doesn't follow program condition). Here is a code: // lab5_q1.cpp : Defines the entry point for the console application. // fstream.cpp // #include <stdafx.h> #include <fstream> #include <iostream> using namespace std; void main() { ifstream InFile; ofstream OutFile; char FirstName[20], LastName[20]; int Score; int Mark; cout << "Please enter your mark: "; cin >> Mark; InFile.open("Records.txt"); InFile >> FirstName >> LastName >> Score; OutFile.open("HighScores.txt"); OutFile << FirstName << LastName << Score; while (!InFile.eof()) { InFile >> FirstName >> LastName >> Score; if (Mark < Score) { cout << FirstName << " " << LastName << " " << Score << endl; OutFile << FirstName << " " << LastName << " " << Score << endl; } } InFile.close(); OutFile.close(); system("pause"); } Note: if you want to test this code just create file records.txt with example names i.e John Doe 65 Jane Smith 42 Carl Young 59 Sarah Jones 77 Kevin Harris 68 Chris Billington 73 I bet it's simple but i'm groping. ![]() Thanks |
| |
| | #2 | |||||
![]() Join Date: Aug 2005 Location: Alton, Hampshire
Posts: 1,376
Thanks: 119
Thanked 91 Times in 86 Posts
Rep Power: 28 | It's been a while since I did any C++, I should do this too... Quote:
Quote:
Code: InFile.open("Records.txt");
OutFile.open("HighScores.txt");
Quote:
Quote:
Quote:
![]() -- David Hicks | |||||
| |
| | #3 |
![]() Join Date: Apr 2008
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Rep Power: 0 | Works.. Thank You David.. Seems like i didn't pay attention somewhere Greg |
| |
| |
| | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Simple 1.5 doesn't look right | SimpleSi | EduGeek Joomla 1.5 Package | 7 | 25-05-2008 11:21 AM |
| Simple php framework | Jona | Web Development | 2 | 02-05-2008 02:43 PM |
| Simple Gallery | Scotmk | Web Development | 2 | 05-03-2008 01:14 PM |
| I love a simple solution | laserblazer | General Chat | 34 | 12-10-2007 12:26 PM |
| Cheap and simple NAS | adamyoung | Hardware | 3 | 21-12-2006 09:52 AM |
| Tags |
| c++, code, programming |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search Thread |
|
|








