Topic: Structs, Functions, and i/o usage


Author: richkow@aol.com (RichKow)
Date: 23 Sep 1994 14:40:07 -0400
Raw View
I am just learning C++.  I don't understand how to use structs if you have
more then just the function main( ).  Here is my program

#include <conio.h>
#include <iostream.h>
#define spc " "
#define totalhs 30
struct play {
 char lsname[15];
 int rating;
 int numbers;
};
int center(int);
int addply(play);

int main(void)
{
 struct play player[1000];
 int count;
 int choice;
 clrscr();
 center(8);
 cout << "                       What would you like to do ?\n";
 cout << "                       ---------------------------\n";
 cout << "                        1) Add a new player\n";
 cout << "                        2) View a player\n";
 cout << "                        3) Quit\n";
 cout << "                       ---------------------------\n";
 cout << "                       Enter the number of your choice ";
 cin >> choice;
 switch(choice)
 {
  case 1:
   addply(player[1000]);
   break;
  case 2:
   cout << "You entered 2";
   break;
  case 3:
   cout << "You entered 3";
   break;
  default:
   cout << "You entered something weird";
  }
}

int center(int lines)
{

 int x;
 for (x = 1; x < lines; x++)
  cout << "\n";
}
int addply(play player[1000])
{

 long int numb;
 clrscr();
 center(9);
 cout << "                        Please enter their player # - ";
 cin >> numb;
 player[numb].numbers = numb;
 cout << "Their player # is " << player[numb].numbers;
}

This program does not compile though.
I need some help on what I am doing wrong.
I also am wondering if it is better to use cout and cin or fprint and
fscan for i/o.

Rich Kowalczyk
RichKow@aol.com