Jump to content

greguk

Members
  • Posts

    4
  • Joined

  • Last visited

Reputation

0 Neutral

About greguk

  1. Works.. Thank You David.. Seems like i didn't pay attention somewhere Greg
  2. Hi, 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 #include #include 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
  3. I'm not a spam program. Maybe i didn't precise question right but i just want to have general outlook if anyone have any C++ experience to help me. i didn't want to post my entire program. My program have to read data from file, store them and add new records to the end of this file.
  4. I have a program for my assignment but I'm struggling with reading/writting to file. If anyone can help I'll be more than happy. if(!ReadRecords("C:\\PDI\\Quotes.txt",Quotes, NumRecords)) { cout << "Failed to find file quotes.txt"; } else { do { system ("CLS"); if(i==0) Quote.QuoteNum =INITIAL_QUOTE_NUMBER; else Quote.QuoteNum =Quotes[NumRecords-1].QuoteNum+1; Quotes[NumRecords]=GetQuote(Quote); NumRecords++; cout << "\n\nEnter another quote?"; cin >> AnotherQuote; } while(AnotherQuote=='Y'||AnotherQuote=='y'); file exist on disk in that location.
×
×
  • Create New...