I am writing programs for a Advanced Programming class. The classes are merged witht the kiddies learning True-BASIC, the C++ kids learn basicly on our own and code the BASIC programs to C++.
Being a noob at C++, I must inquire;
This week the BASIC kids were working on READ-DATA segments in thier class... But me and the other C++ kids thin these would be equivalent to arrays or strings or maybe even a class, we have no idea where to start. Here is a breif summery of the program we are supposed to write:
Write a program that has an internal datadase of 10 Colleges w/ mascots. Let the user input the number of colleges to display at one time... Here is what the output might look like;
Code:
Number of colleges to display: 2
College State Mascot:
---------------------------------------
UNL NE Huskers
Greenbay MN Packers
Here is my code so far if it helps;
Code:
Code:
#include <iostream>
#include <fstream>
#include <stdlib.h>
#define BUFFER_SIZE 1000
//Using global variables incase needed in another fuction
FILE* fp;
//char fname[256]; //Filename.
int i; // i and
int j; // j are variables for the for-loop coming up.
int many; // Number of colleges to display
char buff[BUFFER_SIZE+1];
char ch;
using namespace std;
int main () {
// Input
cout << "How many colleges would you like to display?: ";
cin >> many;
//File stuff
ifstream database ("college.db");
if (! database.is_open()){
cout << cout << "\n\n"
<< "Can't open the input file for reading..." << "\n"
<< "Make sure the input file exists,"
<< "or and application is not using it.\n\n";
system("PAUSE");
}
while (! database.eof() ){
database.getline (buff,1000);
cout << buff << endl;
}
}
system("PAUSE");
return 0;
}
I wan to use a for loop to read a corresponding line of the file to the screen.. eg: you type "two" for how many colleges you want to display... And When you hit "Enter" it reads two lines of the "colleg.db" file to the screnn... each line having the info for the college.
-Thanks!