here is a rough draft.. i don't have time but i have gotten help in the past and i feel obligated to extend any help i can; unfortunately time only permits me to give you a rough idea.. i didn't change much from your original file, except things where you say "if answ = P" when it should be "if answer == 'P'"
good luck, hope you do well.
#include <iostream>
#include <fstream>
#include <cctype> // for tolower/toupper
using namespace std;
struct InfoType
{
string GameName;
string Rarity;
float Price;
}
void GetInfo( ifstream&, InfoType& );
int main()
{
char ANSW; //input to determine order
ifstream gamesFile; //input from file
InfoType entry;
gamesFile.open("c:\games.dat");
if ( !gamesFile) {
// this means we couldn't open the file, let's exit program
cout << "File did not open properly!" << endl;
exit(1);
}
cout << "This program is meant to organize my Nintendo games." << endl ;
cout << "How would you like them to be ordered? By Rarity or Price (R or P) ";
cin >> ANSW;
// change answer to uppercase, and this returns only first char of input as well (which is nice)
ANSW = toupper(ANSW);
SortFiles(ANSW); // sorts file into array by price or rarity
GetInfo(gamesFile, entry); // priming read
while ( !gamesFile.eof() ) { // while not at end of file...
GetInfo(gamesFile, entry);
}
}
//----------------------------------------------------------
void SortFiles(char ANSW) {
if ( ANSW == 'P') {
// basically you want read while not at end into an array
// then you will sort it (your book must have something on
// sorting arrays)
} else if ( ANSW == 'R' ) {
// basically you want read while not at end into an array
// then you will sort it (your book must have something on
// sorting arrays)
}
return;
}
void GetInfo(
/ inout / ifstream& InfoFile, // input file
/ out / InfoType& entry ) // Move to next record
// Prints the game name, rarity and price
{
cout << entry.GameName << ' ' << entry.Rarity << ' ' << '$';
cout << entry.Price << endl;
}