Thread: How do i ouput multiple inputs?

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    12

    How do i ouput multiple inputs?

    i have a program that uses a do while loop to repetitively ask certain question and i need to output all the information that the user inputs for those question in a organized chart. my problem is it only outputs the last set of data i input.How do i output the other data i have already inputted?
    Code:
    #include <iomanip>
    #include <string>
    #include <iostream>
    using namespace std;
    
    int main ()
    { 
    	int yearsofservice,yearhired,oldsalary,code;
    	int numfaculty,totsalaryincrease,avgsalaryincrease;
    	int facultycounter=1;
    	  double newsalary;
    	  double salaryincrease;
    	    const int YEAR=2007;
               string fname;
    	       string lname;
    	           cout<<"How many faculty members are you inputting?:";
    		           cin>>numfaculty;
    	do
    	{
    	
    		  
    		cout<<"Input the members name:";
    		  
    		  cin>>fname>>lname;
    		  
    		  cout<<"Input the members year hired:";
    		     
    		  cin>>yearhired;
              
    			 cout<<"Input the members old salary:";
    		     
    		  cin>>oldsalary;
    		  
    			 cout<<"Input the members code:";
                 
    		  cin>>code;
    		  
    			 switch (code)
    		  {
    				case 1:  salaryincrease=oldsalary*(.03);
    					break;
    				case 2:  salaryincrease=oldsalary*(.05);
    					break;
    				case 3:  salaryincrease=oldsalary*(.08);
    					break;
    				default: cout<<"You did not type any code in!!!";
    		  }
    		        
    		  newsalary=salaryincrease+oldsalary;
    		        
    				yearsofservice=YEAR-yearhired;
    	
    	}while (facultycounter++ <numfaculty);
    cout<<"Robert Dobler\n\n\n";
    
    
    cout<<setw(57)<<"FAILNONE UNIVERSITY FACULTY SALARY REPORT FOR "<<YEAR<<endl<<endl<<endl<<endl;
    
    
    cout<<setw(10)<<"FACULTY"<<setw(17)<<"YEARS OF"<<setw(11)<<"OLD"<<setw(11)<<"NEW"<<setw(17)<<"SALARY"<<endl;
    
    
    cout<<setw(8)<<"NAME"<<setw(19)<<"SERVICE"<<setw(13)<<"SALARY"<<setw(11)<<"SALARY"<<setw(16)<<"INCREASE"<<endl;
    
    
    cout<<setw(10)<<"-------"<<setw(17)<<"--------"<<setw(13)<<"------"<<setw(11)<<"------"<<setw(16)<<"--------"<<endl;
    
    
    cout<<fname<<lname<<setw(12)<<yearsofservice<<setw(16)<<oldsalary<<setw(11)<<newsalary<<setw(14)<<salaryincrease<<endl;
    		return 0;
    }

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Perhaps you'd want to do the output inside the loop.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    18
    Maybe this?>>

    Code:
    #include <iomanip>
    #include <string>
    #include <iostream>
    using namespace std;
    
    int main ()
    { 
    	int yearsofservice,yearhired,oldsalary,code;
    	int numfaculty,totsalaryincrease,avgsalaryincrease;
    	int facultycounter=0;
    	double newsalary;
    	double salaryincrease;
    	const int YEAR=2007;
            string fname;
    	string lname;
    	  
            cout<<"How many faculty members are you inputting?:";
    	cin>>numfaculty;
    
    	while(facultycounter < numfaculty)
    	{ //begins loop
      
    		cout<<"Input the members name:";
    		  
    		cin>>fname>>lname;
    		  
    	        cout<<"Input the members year hired:";
    		     
    		cin>>yearhired;
              
    		cout<<"Input the members old salary:";
    		     
    		cin>>oldsalary;
    		  
    	        cout<<"Input the members code:";
                 
    		cin>>code;
    		  
    	        switch (code)
    		  { //start of switch
    				case 1:  salaryincrease=oldsalary*(.03);
    					break;
    				case 2:  salaryincrease=oldsalary*(.05);
    					break;
    				case 3:  salaryincrease=oldsalary*(.08);
    					break;
    				default: cout<<"You did not type any code in!!!";
    		  } // end of swicth
    		        
    		  newsalary=salaryincrease+oldsalary;
    		        
    		  yearsofservice=YEAR-yearhired;
    
    
    if(facultycounter < numfaculty)
    {// begins if
    cout<<"Robert Dobler\n\n\n";
    
    
    cout<<setw(57)<<"FAILNONE UNIVERSITY FACULTY SALARY REPORT FOR "<<YEAR<<endl<<endl<<endl<<endl;
    
    
    cout<<setw(10)<<"FACULTY"<<setw(17)<<"YEARS OF"<<setw(11)<<"OLD"<<setw(11)<<"NEW"<<setw(17)<<"SALARY"<<endl;
    
    
    cout<<setw(8)<<"NAME"<<setw(19)<<"SERVICE"<<setw(13)<<"SALARY"<<setw(11)<<"SALARY"<<setw(16)<<"INCREASE"<<endl;
    
    
    cout<<setw(10)<<"-------"<<setw(17)<<"--------"<<setw(13)<<"------"<<setw(11)<<"------"<<setw(16)<<"--------"<<endl;
    
    
    cout<<fname<<lname<<setw(12)<<yearsofservice<<setw(16)<<oldsalary<<setw(11)<<newsalary<<setw(14)<<salaryincrease<<endl;
    ++facultycounter;
    } // ends if
    } // ends loop 
    else
    return 0;
    }
    Maybe you could use a loop like that.
    Last edited by Conspiracy; 11-19-2007 at 09:59 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. checking inputs meets multiple conditions
    By 60beetle60 in forum C Programming
    Replies: 5
    Last Post: 04-19-2008, 08:25 AM
  2. Monitors Supporting Multiple Inputs
    By SlyMaelstrom in forum Tech Board
    Replies: 3
    Last Post: 08-22-2006, 04:15 PM
  3. Multiple sound inputs to one output
    By DonR2 in forum C++ Programming
    Replies: 8
    Last Post: 06-23-2004, 04:37 PM
  4. multiple inputs of multiple types
    By frontz in forum C Programming
    Replies: 8
    Last Post: 01-19-2004, 02:57 PM
  5. Getting multiple inputs using cin
    By edk in forum C++ Programming
    Replies: 2
    Last Post: 09-13-2001, 02:34 PM