Thread: c problem to solve

  1. #1
    Registered User
    Join Date
    Jan 2016
    Posts
    3

    c problem to solve

    I'm a freshman student, just started learning c language and our instructor asked me to make a program out of a certain problem. Please, can anyone help me make the program?

    Here's the problem:
    "A government research lab has concluded that certain chemicals commonly used in foods will cause death in laboratory mice. A friend of yours is desperate to lose weight but cannot give up soda pop. Your friend wants to know how much diet soda pop it is possible to drink without result a dying. Write a program to supply the answer. The input to the program is the amount of artificial sweetener needed to kill a mouse, the weight of the mouse, and the weight of the dieter, to ensure the safety of your friend, be sure the program requests the weight at which the dieter will stop dieting, rather than the dieters current weight. Assume that diet soda contains one-tenth of 1% artificial sweetener."

    These are the topics that my instructor had discussed to us about C: Algorithm, Flowcharting and Basic program structure and arithmetic operators. These are the only things we could use for the program(no logical operators, loop, array and etc..). Please someone help me make and explain how you come up with the program?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    It sounds like you just need to implement a formula.
    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 2015
    Posts
    28
    Have you considered not consuming the artificial sweetener at all?

    Your friend's safety will be ensured and he'll probably lose weight as a result.

    Additionally, he'll learn some self control and you won't have to waste your effort on an unnecessary task.

    edit: And you won't have to kill mice to get inputs for your program.
    Last edited by danielcamiel; 01-13-2016 at 12:44 AM.

  4. #4
    Registered User
    Join Date
    Jan 2016
    Posts
    3
    Thanks for that answer daniel, well it help a lot. Now I know another stupid person.

  5. #5
    Ticked and off
    Join Date
    Oct 2011
    Location
    La-la land
    Posts
    1,728
    I agree with Laserlight. I shall just expand a bit on that, if I may.

    Your program needs to parse the inputs (by prompting the user and then scanning from standard input, it looks like; you should have done that in an earlier exercise already), apply the formula to find out the result, and print the result.

    From your original post, we see that the inputs are
    • amount of artificial sweetener needed to kill a mouse
    • the weight of the dead mouse
    • the weight of the dieter (minimum weight, limit for dieting)

    The formula you need to devise tells the amount of artificial sweetener to kill the dieter. (Yes, it is a very simple formula. It is not a hard exercise.)

    You were also told that soda pop contains 0.1% of artificial sweetener (= 1/1000). Because no other properties were given for the soda pop, you must use the same units (weight or volume) for both the soda pop and the artificial sweetener. Or, if you prompt the user to use specific units, you can convert between those units. (I'd use grams to avoid that, but if you have had an exercise about unit conversions, revisit those.)

    Of course, the two weights must be in common units to be comparable. It is good to remind the user about that, so they don't supply e.g. 15 for the weight of the mouse (thinking it means 15 grams, because mice are small) and 10 for the final weight of the dieter (thinking it means 10 stones, because people are large). The units for the two weights do not actually matter at all, as long as they're the same, because the formula only uses their ratio.

    It is quite straightforward. In problems like these, you just need to take the problem statement apart, and focuse on each part at a time, possibly rewriting in your own words on paper, listing given inputs, constants, and required outputs, until it makes sense.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can anyone solve this problem for me
    By s000p222 in forum C++ Programming
    Replies: 15
    Last Post: 05-30-2012, 10:19 AM
  2. how to solve this problem?
    By lijr07 in forum C++ Programming
    Replies: 13
    Last Post: 07-30-2011, 12:53 PM
  3. Please help me to solve this IO problem.
    By nichya88 in forum C++ Programming
    Replies: 2
    Last Post: 01-19-2010, 12:15 PM
  4. how do i solve this problem?
    By manav in forum A Brief History of Cprogramming.com
    Replies: 31
    Last Post: 04-15-2008, 09:58 AM
  5. problem cant solve please help.
    By sarah in forum C Programming
    Replies: 6
    Last Post: 09-03-2001, 01:32 PM

Tags for this Thread