Printing From Struct

This is a discussion on Printing From Struct within the C++ Programming forums, part of the General Programming Boards category; Hey guys I have a quick question. I am trying to print from a database within a struct. I need ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    133

    Printing From Struct

    Hey guys I have a quick question. I am trying to print from a database within a struct. I need it to hold information for five employees hence the MAX being five. However I am trying to test it for just one employee because there is just simply a lot of data to enter. Once the data is entered it does not print any of the entered data and the formatting is all off. Any ideas? Thanks!


    Code:
    #include <iostream>
    
    	int id_Num;
    	int hours;
    	float gross;
    };
    
    employeeType Database[MAX];
    
    int main()
    {
    	int i;
    
    	for (i = 1; i < 2; i++)
    	{
    		cout << "Please enter information for employee number " << i << ": " << endl;
    		cin >> Database[i].id_Num >> Database[i].employee.last >> Database[i].employee.first >> Database[i].employee.mid 
    			>> Database[i].dob.day >> Database[i].dob.month >> Database[i].dob.year >> Database[i].rate >> Database[i].hours 
    			>> Database[i].starting.day >> Database[i].starting.month >> Database[i].starting.year
    			>> Database[i].supervisor.last >> Database[i].supervisor.first >> Database[i].supervisor.mid;
    		Database[i].gross = (float)(Database[i].hours * Database[i].rate);
    	}
    
    	int j;
    
    	cout << "Number  Name(last, first, middle)  DOB        Rate  Hours  GrossPay   StartingDate  Supervisor(last, first, middle)";
    	for (j = 1; j <2; j++)
    	{
    			cout << Database[i].id_Num << "  " << Database[i].employee.last << " " << Database[i].employee.first 
                                    << " " << Database[i].employee.mid << "  " << Database[i].dob.day << "-" << Database[i].dob.month 
                                    << "-" << Database[i].dob.year << "  " << Database[i].rate << "  " << Database[i].hours << " " 
                                    << Database[i].gross << "  " 
                                    << Database[i].starting.day << "-" << Database[i].starting.month << "-" << Database[i].starting.year << "  " 
                                    << Database[i].supervisor.last << "  " << Database[i].supervisor.first << " " << Database[i].supervisor.mid;
    
    	}
    	return 0;
    
    }
    Last edited by GCNDoug; 02-20-2008 at 08:50 PM.

  2. #2
    Registered User
    Join Date
    Apr 2007
    Posts
    133
    lol it wasn't printing cause I used i instead of j for the display. Any help with the formatting would be greatly appreciated though lol

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. linked list question
    By brb9412 in forum C Programming
    Replies: 16
    Last Post: 01-04-2009, 03:05 PM
  2. Replies: 1
    Last Post: 12-03-2008, 02:10 AM
  3. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  4. Binary Search Tree
    By penance in forum C Programming
    Replies: 4
    Last Post: 08-05-2005, 05:35 PM
  5. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 05:58 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21