Thread: Help to write min,max program for a project

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

    Help to write min,max program for a project

    I have an assigment and I don't know yet how to write this program :" I introduce the average monthly temperatures of a year(12 values for 12 months). When I compile the program it needs to show the highest negative temparature and the lowest positive temperature of that year. Example: Entry data: -4 -6 0 5 10 20 24 25 17 8 -1 -7 exit data : max negative= -1 and min positive= 5 "

    I can pay a few dollars through paypal but I'm from Romania so I don't have much, I need the program in maximum 12 hours from now, please help.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    There are two ways that I might start with:

    1. Write a program to get the monthly temperatures and print them. This will give me confidence that I can do the basic input and output correctly. After that, I can work on the core algorithm of the exercise.

    2. Hard code a suitable set of month temperatures, design and implement an algorithm to find the maximum negative temperature, and then print it. This will give me confidence that I can do the algorithm that forms the core of the exercise. After that, I can figure out how to change it to also find the minimum positive temperature (what about 0 degrees?), and get it to read input properly.

    Pick one of these two approaches and get started. If you get stuck, you can ask for help by posting your current program and explaining how does it not work.
    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
    Jan 2014
    Posts
    3
    @laserlight thank you, I understand that you're REALLY wanting to help me by guiding me,I really do, but I just started to learn C and I find it very difficult for my head, I just want to do this project for a minimal grade at school, I don't think I can become a programmer, if someone can write the whole program I'll pay for it, 5$ or 10$ whatever they ask,please help, it's very important for me to pass the course.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by nightwolf9ss
    I just started to learn C and I find it very difficult for my head
    That's why both the approaches I described does not require you to do everything at once: solve the problem by breaking it down into steps, thus solving it step by step. To solve a particular step, you might need to review your learning material, ask for help in understanding it, or even experiment and break it down into smaller steps, etc.

    Quote Originally Posted by nightwolf9ss
    I just want to do this project for a minimal grade at school, I don't think I can become a programmer, if someone can write the whole program I'll pay for it, 5$ or 10$ whatever they ask,please help, it's very important for me to pass the course.
    I could say the same thing about pretty much any subject at school: I don't think I can become a professional mathematician; I don't think I can become a professional historian. It would not change the fact that getting/paying someone else to do my maths homework or write my history essay would be cheating. Academic dishonesty could result in an immediate failure of the course, perhaps even expulsion from your academic institution, so if it is very important for you to pass the course, then you should start working on your assignment, step by step.
    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

  5. #5
    Registered User
    Join Date
    Nov 2012
    Posts
    157
    if you stopped looking to buy the solution and tried to do it for yourself, you would find that 12 hours is more than enough time to come up with a solution to your task.

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    If you remain calm, and work on it, you have time.

    The problem is no different from someone handing you a bunch of coins, and asking you to find the one that is worth the most, and the one that is worth the least, out of the coins. You would need to compare every coin to the coin that was the previous maximum, as well as the previous minimum, correct?

    Sounds like a loop could be used here, doesn't it?

    Code:
    for( each coin) 
    {
        if the coin is > the value of the maximum coin found so far,
            then the coin value becomes the new max value.
    
       if the coin is < the value of the minimum coin found so far,
          then the coin values becomes the new min value.
    }
    The above is the basic logic you would use, but the silly computer (lacking common sense), won't know how to set the initial max and min values. With coins you could start at zero, since there are no negative values possible. With temperatures, negative values are common though. One answer is to set the maximum and minimum values to the first value you look at, before the for loop starts. Then start the for loop, comparing the second value, instead of the first one.

    Remember that in C, you want to use arrays for this, and array indices start at zero, not one. So the first value is array[0], second value is array[1], etc.

  7. #7
    Registered User
    Join Date
    Jan 2014
    Posts
    3
    Thank you all for trying to help me, you were right ,I got the program "ready made" and the teacher asked me if I wrote it and I had to tell her I did not and the look on her face..... I felt ashamed the whole day, I'm not very young anymore and learning new things come hard for me but still I should've tried,my bad.

  8. #8
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    The teacher probably had a fair inkling you hadn't done the work, otherwise she wouldn't have asked the question.

    Students the world over think they can fool teachers. The problem is, since most teachers are or were students themselves, most know the tricks that get created (ahem, reused) by each new group of students. Every new crop of students think they have created a new way to fool teachers without doing the work, but very few actually have.

    If the teacher actually knows something about the subject, s/he is even more likely to pick up a cheating student. It is easy for a novice to trick a novice. The chances of a novice tricking an expert are remote.
    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.

  9. #9
    Registered User
    Join Date
    Jan 2014
    Posts
    5
    Lol yah you can take the program for the internet that's normal

    but at least try to study what did u take and understand it

  10. #10
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Lol yah you can take the program for the internet that's normal
    Sadly, it is normal. When I went to school, several people spent a lot of energy collecting programs that were solutions for all laboratory assignments. I was often offered these solutions from one particular individual. I always turned them down because, well, I wanted to actually learn it on my own. I ran into that guy last year. He works at a Volkswagen dealership, whereas I hold an engineering position. If he spent as much energy learning the material as he did in trying to acquire a comprehensive set of solutions written by others, perhaps he would have better employment today.

    but at least try to study what did u take and understand it
    I'd argue that, at best, one would only understand a tiny fraction of the solution. A person might think they understand something when they see it written out for them - but it's only when trying to write it oneself that true understanding can begin to be achieved.

  11. #11
    Registered User
    Join Date
    Nov 2012
    Posts
    157
    I'd argue that, at best, one would only understand a tiny fraction of the solution. A person might think they understand something when they see it written out for them - but it's only when trying to write it oneself that true understanding can begin to be achieved.
    i can testify

  12. #12
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I'd agree, but the simple concepts are easily grasped just by a quick perusal. For instance, my neighbor's border collie was over visiting, saw my post above, and was immediately able to use it in a small C snippet of code. <smile>

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 08-02-2013, 06:45 PM
  2. How not to write a Project Proposal
    By Mario F. in forum General Discussions
    Replies: 3
    Last Post: 12-14-2009, 01:38 PM
  3. How to write a program
    By Tashfique in forum C++ Programming
    Replies: 4
    Last Post: 10-17-2008, 11:28 AM
  4. How to write a program for...
    By babyboy in forum C Programming
    Replies: 6
    Last Post: 02-15-2008, 06:17 AM
  5. I need to write a program !!!
    By alone2002dj in forum C Programming
    Replies: 2
    Last Post: 12-12-2007, 01:22 AM