Thread: using array to enter number of users and their data

  1. #1
    Registered User
    Join Date
    Dec 2014
    Posts
    1

    using array to enter number of users and their data

    Hi,
    I have a small program to calculate the value of salary. I want to user to be able to enter more than one user using array and finally calculates the average salary of all users.
    Here is the code
    Code:
    #include <iostream>#include <conio.h> 
    using namespace std;
    
    
    int main() {
    	const int months=3;
    	double net_pay;
    	string EmpName;
    	string date_of_birth;
    	int hours, dependents;
    
    
    	cout<<"Please enter your name: " ;
    	cin>>EmpName;
    
    
    	cout<<"enter your birth date: ";
    	cin>>date_of_birth;
    
    
    	
    
    
    	do {
    		cout<<"How many hours you work everyday: (Please                   choose 8, 10 or 12 only): ";
    		cin>>hours;
    	} while(hours != 8 && hours != 10 && hours != 12);
    	
    	cout<< "How many children you have? ";
    	cin>>dependents;
    
    
    	if (0<dependents<10) {
    		if(hours==8) {
    			net_pay= months*300; 
    		} else if (hours==10) {
    			net_pay= (months*300)+(5*dependents);
    		} else if (hours==12) {
    			net_pay= (months*400)+(10*dependents);
    		}
    
    
    		cout<<" Hello "<<EmpName<<"...  Your Salary is "<<net_pay<<endl ;
    	} else {
    		cout<<" Please choose correct values"<<endl ;
    	}
    
    
    	 getch(); 
              
    	return 0;
    
    
    }
    Thanks in advanced

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    What have you tried?

    Seriously, there is no array in that code at all. (except for the minor philosophical aside that a std::string might notionally represent its data using an array).

    Giving code for something, and saying you want to use an array to make it work for multiple somethings, does not cut it for demonstrating at least some effort to solve your own problem (do your own homework).
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    >>if (0<dependents<10)
    Note that C++ does not understand mathematical range notation. This is equal to:

    if ((0 < dependents) < 10)
    which is equal to
    if ((true or false) < 10)
    which is equal to
    if ((1 or 0) < 10)
    which is always equal to true.

    You have to separate them:
    if (dependents > 0 && dependents < 10)
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 08-22-2014, 07:00 AM
  2. Matching data to users
    By EVOEx in forum Tech Board
    Replies: 5
    Last Post: 06-29-2012, 08:07 AM
  3. Users saving data on a text editor
    By htmlmaster in forum C++ Programming
    Replies: 3
    Last Post: 04-17-2005, 06:20 AM
  4. reading data from the users input
    By SpEkTrE in forum C++ Programming
    Replies: 1
    Last Post: 04-10-2005, 06:15 PM
  5. Enter a number
    By bennyho03 in forum C Programming
    Replies: 2
    Last Post: 09-25-2004, 05:51 AM