Thread: Large amount of data input

  1. #1
    Registered User
    Join Date
    Feb 2016
    Posts
    44

    Large amount of data input

    I have this HW problem
    Write the program with two functions to solve the following problem.
    Theres a pay raise for 100 faculty members. They are considering a pay increase of 5%. Write a program that will prompt for and accept the current salary for each of the faculty members, then calculate and display their individual pay increases. At the end of the program, print the total faculty payroll before and after the pay increase.

    Any ideas how I can do this for 100 variables? I cant printf/scanf manually for 100 people can I?

    Just a tip in the right direction would help, thanks!

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Any ideas how I can do this for 100 variables?
    Why do you think you need 100 variables?
    I cant printf/scanf manually for 100 people can I?
    You can, but there are probably easier ways.

    Jim

  3. #3
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Use an array and a loop.

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Is an array even required? It seems that it would be possible to accomplish the objectives with five or fewer variables and no arrays.

    Jim

  5. #5
    Registered User
    Join Date
    Feb 2016
    Posts
    44
    Quote Originally Posted by jimblumberg View Post
    Is an array even required? It seems that it would be possible to accomplish the objectives with five or fewer variables and no arrays.

    Jim
    How could you display individual pay increases for up to 100 people with only 5 variables? Could you help a little more than just telling me that? I dont need the answer to the homework, just a little direction in the right way.

    We have not learned arrays yet in this course, even though i know how to use them, we cant for this problem.

  6. #6
    Registered User
    Join Date
    Feb 2016
    Posts
    44
    Quote Originally Posted by Rednally View Post
    How could you display individual pay increases for up to 100 people with only 5 variables? Could you help a little more than just telling me that? I dont need the answer to the homework, just a little direction in the right way.

    We have not learned arrays yet in this course, even though i know how to use them, we cant for this problem.
    @jimblumberg

  7. #7
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Your assignment doesn't say to print the salaries for all the employees. So just to retrieve the salaries from the user in a loop and compute the total salary. And then print the total current salary at the conclusion of the loop. Lastly compute the new salary for the salary increase and print that value.

    Jim

  8. #8
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Quote Originally Posted by jimblumberg View Post
    Your assignment doesn't say to print the salaries for all the employees.
    Not trying to be annoying, but it does:
    Quote Originally Posted by Rednally View Post
    Theres a pay raise for 100 faculty members. They are considering a pay increase of 5%. Write a program that will prompt for and accept the current salary for each of the faculty members, then calculate and display their individual pay increases. At the end of the program, print the total faculty payroll before and after the pay increase.
    It sounds like you will need a variable for the before increase total, the after increase total, and input salary. Since the array approach is off limits, you will have to interleave input with output.

    For example:

    Enter salary for employee 1: 500
    Employee 1 has an increase of $25, and their new salary is $525.
    Enter salary for employee 2: 1435
    Employee 2 has an increase of $71.75, and their new salary is $1506.75.

    Try coding that.

  9. #9
    Registered User
    Join Date
    Feb 2016
    Posts
    44
    Quote Originally Posted by whiteflags View Post
    Not trying to be annoying, but it does:

    It sounds like you will need a variable for the before increase total, the after increase total, and input salary. Since the array approach is off limits, you will have to interleave input with output.

    For example:

    Enter salary for employee 1: 500
    Employee 1 has an increase of $25, and their new salary is $525.
    Enter salary for employee 2: 1435
    Employee 2 has an increase of $71.75, and their new salary is $1506.75.

    Try coding that.
    Code:
    #include <stdlib.h>
    #include <stdio.h>
    
    
    main() {
    	int i;
    	int sal;
    	int sn;
    	int pr;
    	int salpayraise;
    	int numberCount=0;
    	printf("How many salarys? \n");
    	scanf("%d", &sn);
    	printf("%d salaries\n", sn);
    
    
    	while (numberCount != sn) {
    
    
    		printf("\nEnter Salary: \n");
    		scanf("%d", &sal);
    		pr = (sal * 5) / 100;
    		salpayraise = pr + sal;
    		numberCount++;
    		printf("Salary payraise is: %d and original was: %d", salpayraise,sal);
    	}
    	
    	
    
    
    	system("pause");
    }

  10. #10
    Registered User
    Join Date
    Feb 2016
    Posts
    44
    This was as close as I could get to what I needed.
    Code:
    /*Jake Yllander
    Write program with 2 functions, that shows the pay raise of 5% for up to 100 employees.
    Prompt user to enter salary, calculate and display pay raise for each individual.
    Then print total payroll before and after pay raise.
    
    
    
    
    */
    #include <stdlib.h>
    #include <stdio.h>
    void howManySals();
    main() {
    	int i;
    	int sal;
    	int sn;
    	int pr;
    	int salpayraise;
    	int numberCount = 0;
    	int total = 0;
    	int totalRaise = 0;
    	int sum = 0;
    	int sum2 = 0;
    	howManySals();
    	scanf("%d", &sn);
    	printf("%d salaries\n", sn);
    
    
    	while (numberCount != sn) {
    
    
    		printf("\nEnter Salary: \n");
    		scanf("%d", &sal);
    		pr = (sal * 5) / 100;
    		salpayraise = pr + sal;
    		numberCount++;
    		sum += sal;
    		sum2 += salpayraise;
    		total = sum;
    		totalRaise = sum2;
    		printf("Salary payraise is: %d and original was: %d", salpayraise, sal);
    	}
    	printf("\nTotal salary before: %d, Total salary after: %d \n", total, totalRaise);
    
    
    
    
    	system("pause");
    }
    void howManySals() {
    	printf("How many salaries? \n");
    }

  11. #11
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    That seems to meet the letter of the academic requirement ("write program with 2 functions") without meeting the spirit of the requirement: instead of calling howManySals(), you might as well place the printf there as there is nothing to be gained whether by readability or reusability in having that helper function.

    Rather, if you wanted to call a helper function in that place, a better option would to have the helper function request for the number of salaries, then read the number of salaries, optionally printing it (or the printing could be done in main).

    Another option is to move the entire body of the loop into a helper function dedicated to processing the salary raise for a single salary. You could also move the computation of a salary raise into a helper function.

    By the way, you should avoid cryptic variable names like sal, sn, and pr. Just writing salary, numberOfSalaries (or salaryCount), and payRaise will do. Actually, you don't really need payRaise because you can compute:
    Code:
    salaryAfterRaise = (salary * 5) / 100 + salary;
    speaking of which you should consider if salary values should be of type double rather than int due to integer division. Money values will often be in a fixed point type rather than floating point, but this may be beyond the scope of your exercise (or perhaps you read the salary values in cents).

    Another thing: it looks like you don't need sum and sum2 since they are essentially aliases for total and totalRaise. totalRaise sounds like a poor name though: it is really totalAfterRaise (or payrollAfterRaise since total would be more accurately renamed to payroll), whereas totalRaise could be misinterpreted as the total amount of pay raise, i.e., difference between payroll before the raise and payroll after the raise.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  12. #12
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    One other thing - function main returns an int.
    Double Helix STL

  13. #13
    Registered User
    Join Date
    Feb 2016
    Posts
    44
    Quote Originally Posted by laserlight View Post
    That seems to meet the letter of the academic requirement ("write program with 2 functions") without meeting the spirit of the requirement: instead of calling howManySals(), you might as well place the printf there as there is nothing to be gained whether by readability or reusability in having that helper function.

    Rather, if you wanted to call a helper function in that place, a better option would to have the helper function request for the number of salaries, then read the number of salaries, optionally printing it (or the printing could be done in main).

    Another option is to move the entire body of the loop into a helper function dedicated to processing the salary raise for a single salary. You could also move the computation of a salary raise into a helper function.

    By the way, you should avoid cryptic variable names like sal, sn, and pr. Just writing salary, numberOfSalaries (or salaryCount), and payRaise will do. Actually, you don't really need payRaise because you can compute:
    Code:
    salaryAfterRaise = (salary * 5) / 100 + salary;
    speaking of which you should consider if salary values should be of type double rather than int due to integer division. Money values will often be in a fixed point type rather than floating point, but this may be beyond the scope of your exercise (or perhaps you read the salary values in cents).

    Another thing: it looks like you don't need sum and sum2 since they are essentially aliases for total and totalRaise. totalRaise sounds like a poor name though: it is really totalAfterRaise (or payrollAfterRaise since total would be more accurately renamed to payroll), whereas totalRaise could be misinterpreted as the total amount of pay raise, i.e., difference between payroll before the raise and payroll after the raise.
    Thank you for all of your input!

    Do you know of somewhere that has multiple beginner level problems such as this one, with the answers included? My textbook does not include the answers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. best way to sort large amount of data.
    By jocdrew21 in forum C++ Programming
    Replies: 32
    Last Post: 02-10-2014, 01:11 PM
  2. Help managing large amounts of data and generating data from it
    By jakethehake in forum C++ Programming
    Replies: 0
    Last Post: 12-01-2009, 06:59 AM
  3. Copying constant amount of data
    By TriKri in forum C++ Programming
    Replies: 16
    Last Post: 07-12-2008, 06:32 AM
  4. [Large file][Value too large for defined data type]
    By salsan in forum Linux Programming
    Replies: 11
    Last Post: 02-05-2008, 04:18 AM
  5. Read large amount of numbers from file
    By h3ro in forum C++ Programming
    Replies: 7
    Last Post: 05-10-2007, 09:33 AM

Tags for this Thread