Overclock.net banner

Structures, C++

869 Views 3 Replies 3 Participants Last post by  tofunater
I'm really struggling with this assignment, and need some help. I've created an input file that needs to be printed using two functions, one to build an array, the other to display it, all using structures.

Code:

Code:
#include <iostream>
#include <iomanip>
#include <ctype.h>
#include <fstream>
struct teamInfo 
{
       char schoolName[20];
       char teamName[20];
       int game1score;
       int game2score;
       int game3score;
};
int buildArray();
void displayArray(int);
int main()
{
    teamInfo aTeam[40];
    int numTeams;
    build array(teamInfo aTeam[]);
    displayArray(teamInfo aTeam[], numTeams);
    system ("pause");   
    return 0;
}
//main function is complete    
//Functions need completion.

int buildArray(teamInfo aTeam[])    
{
    teamInfo aTeam[40];
    char aTeam[256];
    int count = 0;
    inFile.open( "results.txt" );
    if ( inFile.fail() )
       {
       cout << "input file did not open";
       exit(0);
       }

    while (infile.read(aTeam,256))
    {
    inFile.read((char*) &aTeam, sizeof(aTeam));

}

void displayArray(teamInfo aTeam[], int numTeams)
{
Thats what I've managed to type so far, but I know that some of it does not make sense. Any one have any pointers?
edit: no pun intended of course...

and here is a direct link to the rest of the assignment if you would like to know where some of the variables come from. I am working on Program 2, the read function.
See less See more
1 - 4 of 4 Posts
Just a quick read & reply... What specifically are you having trouble with at the moment? It's easier to say what your specific problem is at the moment than to just say you're having problems, it's vague & basically leaves it upto the reader to try to either figure it out or do the entire thing.

I see you finish with the displayArray function, but it's clear you haven't tried to compile it, I suggest you write each part & keep compiling & testing it as you go fixing errors you find along the way or you'll end up having to rewrite large parts of code in future or large amounts of problems & so on.

Just some things noticed... displayArray prototype declares an int as the only argument when you implement it's definition & when you try to call it you declare & pass a teamInfo object (or an array to be precise) so you'll need to add that to the prototype.

Using system("PAUSE") is bad practice in general, it's not portable & thus generally frowned upon, if you want to pause a console window for a key use a more portable solution like std::cin.get(); which you'll then need to press enter to continue but it'll do the same job while being both lighter & standard/portable.

Oh yea also the while loop in buildArray hasn't got a closing brace & since the function has a return value then you should add one. (Hint: Your link says to return the amount teams in the array)
See less See more
  • Rep+
Reactions: 1
Nak is right, you need to look this over more yourself then present a question.
I was going to mention cin.get / getch myself but I see he covered that. System() is actually a security problem as well, which is also why we dont use it.
  • Rep+
Reactions: 1
I forgot I even posted this. It was late and I was panicky. I try to be more professional than this, sorry guys.
Btw, I turned this program in a while ago, and am officially done with this class as of last Tuesday. Much thanks to those who helped me get through this course. You guys are the best
See less See more
1 - 4 of 4 Posts
This is an older thread, you may not receive a response, and could be reviving an old thread. Please consider creating a new thread.
Top