Thread: Need help solving this C programming question

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    5

    Need help solving this C programming question

    Hello,

    I am new to C programming, can anyone help me solving this issue, the actual question is actually longer.. i edited the question to make it shorter so i could try it my own.


    The following Table 1 that manipulates a two-dimensional array stores the work hours for three employees. Each row stores the employee’s seven-day work hours with seven columns. Write, run and test a C program that reads the hours, calculates total hours and salary and displays all fields, employee’s total hours and salary.

    Note: Weekdays salary rate: RM4.50 per hour
    Weekend salary rate : RM8.00 per hour


    PTimer Mon Tue Wed Thu Fri Sat Sun
    Adam 3 4 5 5 3 4 2
    Ricky 4 3 4 6 5 4 3
    Jane 4 5 5 3 3 4 4





    TABLE 1: Part-time Working Hours







    Sample output:

    Ptimer Mon Tue Wed Thu Fri Sat Sun Total Hours Salary
    Adam 3 4 5 5 4 4 2 27 $142.50





    TABLE 2: Sample output

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What have you tried?
    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

  3. #3
    Registered User
    Join Date
    Oct 2011
    Posts
    5
    I have not try the question yet, I don't know how to begin. I am an online learner so I don't have anyone to discuss with. I am considered a beginner with C program. All I have done so far is surf the net, learn and try few basic things about array. I really have no idea on how to do it. I really need help. The actual question is longer than that, i edited it so i can try my own later once I get a reply from someone on how to answer the question.

  4. #4
    Registered User
    Join Date
    Sep 2011
    Location
    Stockholm, Sweden
    Posts
    131
    The first thing you must do is to read the data into your program. I would suggest reading some C-tutorials on how to read data from files to begin with. When you have the data in your program, move on to the next task.

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by C-user View Post
    I have not try the question yet, I don't know how to begin. I am an online learner so I don't have anyone to discuss with. I am considered a beginner with C program. All I have done so far is surf the net, learn and try few basic things about array. I really have no idea on how to do it. I really need help. The actual question is longer than that, i edited it so i can try my own later once I get a reply from someone on how to answer the question.
    Ok... 4 steps...

    ANAYSE the problem until you understand it in little tiny bits, the way a computer would. If you can't describe it in words, you don't understand it well enough.

    PLAN your solution to the problem... make a step by step list of exactly what the program has to do... again in little tiny computer like steps.

    WRITE your code... work in small sections according to your plan compiling and testing as you go.

    TEST your code and find any problems.


    Next... if your lonline course isn't giving you enough information to write this assignment, get hold of whoever is sponsoring it and tell them so. Most reputable colleges and universities will be eager to fix any problems in their curriculum.

    In any case... you need to get your hands on a decent C Programming book (yeah old school but still the best way)... start on page 1, read the text --every word-- repeat if necessary, type up the examples and quizzes, play with the code until you understand what does and does not work... then turn to page 2... repeat until you get to the end of the book.

    This forum is here to help people with problems in their source code... while we do explain some things, we are not volunteer teachers and we most certainly don't do people's homework for them...

    You can read the homework policy -> HERE

    Now, once you have some code together, should you run into troubles, post it here and ask specific questions... we'll see what we can do.

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    ANALYSE -> PLAN -> WRITE -> TEST

    You know that can't be right! APWT?? APWT??? That is just NOT a catchy acronym!

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Adak View Post
    ANALYSE -> PLAN -> WRITE -> TEST

    You know that can't be right! APWT?? APWT??? That is just NOT a catchy acronym!
    You got a better one?

  8. #8
    spaghetticode
    Guest
    How about "MOSSAD"? -> 1) Mentally organise your task --- 2) Structure your ideas on a sheet of paper --- 3) Actually code your solution --- 4) Drive some tests.

  9. #9
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Alas no, I am not an A.S.S: (Assiduous Acronym Studier). And clearly, this should be your project, young man. We have a homework policy here, you know!

    Go write a program to find the best one possible.

    My vote is on: APACT, but it should be something like APLAN.

    Well, it worked for the Panama Canal palindrome:
    "A man, a plan, a canal, Panama"

    That was pure genius!

    Mossad? You WANT to get a billions Muslims ticked off at us?
    Last edited by Adak; 10-18-2011 at 06:00 AM.

  10. #10
    spaghetticode
    Guest
    Quote Originally Posted by Adak View Post
    Mossad? You WANT to get a billions Muslims ticked off at us?
    Good point there. Though I highly doubt that the part of the Muslim community that would tick off for things like that are concerned with reading the cprogramming.com message board. I nevertheless apologize to all our muslim brothers and sisters for such a tactlessness.

  11. #11
    Registered User
    Join Date
    May 2006
    Posts
    10
    Write a pseudo-code or just code your assignment in any language you feel comfortable. Once you have it done translating to C wouldn't be any hard, the logic behind its simple enough for you to reach it by yourself. If you have any problems compiling the program then get back to the forum.

  12. #12
    Registered User
    Join Date
    Oct 2011
    Posts
    5
    The problem is I really don't have time to study, most of the time I am busy with work and I'm running out of time. At least please give me hints/method how to do the question.

  13. #13
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You need to somehow find / make the time for your C class assignments. We can't help you with that. Learning C takes time and lots of it.

    Your assignment says to use an array, with rows and columns, so get started with a C program, (just a skeleton), that declares the number of rows you need, and the seven columns you need.

    You'll also need a FILE pointer and some variables - your hours can be all int's since they have no fractional hours. Your pay_rate and pay_day, and pay_week variables, could be handled easiest by double data type.

    Do you have the file to test your program on? The details of that file's organization are important to your program choices.

    It's up to you to get this started, in an actual C program. If you get stumped, post back with your code (and use code tags fcol), and we'll help you get past that sticking point.

  14. #14
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by C-user View Post
    The problem is I really don't have time to study, most of the time I am busy with work and I'm running out of time. At least please give me hints/method how to do the question.
    That's what people have been doing.

    We don't hand out free code (unless it's really trivial) and there is a forum policy against doing people's homework for them.

    Give this your best shot... if you get stuck post the code you've been working on and maybe we can give you some hints....

  15. #15
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by C-user View Post
    I have not try the question yet, I don't know how to begin.
    I'll tell you exactly where to begin. You begin with:
    Code:
    int main(void)
    {
    }
    And perhaps some #includes at the top.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Solving a more difficult math equation in c programming
    By karma_jesus45 in forum C Programming
    Replies: 9
    Last Post: 09-14-2011, 06:34 PM
  2. Replies: 2
    Last Post: 06-21-2011, 10:08 AM
  3. Help solving a question
    By everyone0 in forum C Programming
    Replies: 9
    Last Post: 05-06-2010, 11:09 AM
  4. Help solving this loop question
    By everyone0 in forum C Programming
    Replies: 2
    Last Post: 05-05-2010, 11:33 AM
  5. Solving this problem with C programming
    By schadenfreude in forum C Programming
    Replies: 4
    Last Post: 03-02-2009, 05:25 PM