February 8th, 2013, 06:09 PM
Since there are only 86400 seconds in a day, an int could very easily contain seconds. So seconds would be declared as an int.
Belay that last!
What compiler are you using? If it's an ancient 16-bit compiler, then an int would only be 16 bits long, such that a signed int only had a range of about -32,768 to 32,767. If it's a newer 32-bit compiler, then an int would range between +/- 2 billion+.
If you are using a 32-bit compiler, then an int would suffice. If you are using a 16-bit compiler, then you had better declare seconds to be a long.
Last edited by dwise1_aol; February 8th, 2013 at 06:36 PM.
February 8th, 2013, 06:52 PM
im using a 32-bit compiler, its called putty
Originally Posted by dwise1_aol
im asking how would you write the seconds calculation for my program?
February 8th, 2013, 08:45 PM
O...K ... .
Originally Posted by mjmjmjmj
If I were to 2 items for $.75 each and 4 items for $1.23 each, then
total_cost = 2 * .75 + 4 * 1.23;
Why do you find that so difficult?
February 9th, 2013, 01:42 AM
Yes, and how did you manage that?
Originally Posted by mjmjmjmj
Using a calculator perhaps?
If so, just how hard can it be for you to replicate your calculator key presses in a line of code?
int variablename = 3600 <a calculator operator> <a number> ......
Follow that up with
printf("The number of seconds=%d\n", variablename );
You've already done the hard part, just write down what you did as a line of code.
Is this the first program you've ever written which isn't just printf and scanf?
February 9th, 2013, 03:04 AM
mjmjmjmj, let me pick up on what salem just told you.
Back in the day, when computers were people rather than machines (that switch happened very shortly after WWII), we did all our record keeping and book keeping and administrative work by hand. We wrote it all down on pieces of paper and we filed those pieces of paper away in an orderly manner so that our clerks could then retrieve a desired piece of paper upon demand. The general term for all that was manual methods.
With the introduction of commercial computers after WWII, we started to convert those manual methods over to automated methods. The conceptual bases for most of our automated methods are based almost directly on the old manual methods. The killer app for the Apple II, VisiCalc, was based directly on an accounting tool, the spreadsheet. Accounting software such as Quicken is based on the old accounting journals with their debits and credits (terms which do not mean what you think they do).
So then, many times when you write a program, you are to take a manual method and automate it. When you do that, you need to understand the manual method so that you can translate it to a working program.
This clocks program, like so many of the other programs you will be assigned, is such a case where you have a manual method that you must translate to a working program. Understand the manual method and the translation will be simple ... usually ... sometimes ... much of the time.
Some more intimate sharing now.
How many human languages have you learned? After having learned your first foreign language, you have also learned how to learn another language. There are many more languages than just human languages. For example, there are programming languages. There is also mathematics and algebra.
When I was in high school (ages 16 through 18, after which comes college or university), I had a problem in algebra class. I had no problem with the algebra itself; in elementary school, I had taught myself most of it from my older sister's textbook. But word problems were always a problem for me. I could never figure out how to set up the algebraic problem based on the word problem. So in high school I gave up on mathematics and started college as a foreign language major.
But then a few years later (early 1970's), PBS (public broadcasting system in the USA) carried a series of lectures by conductor/composer Leonard Bernstein on a pet theory of his, musical linguistics. At one point, he described a linguistical spectrum from the most concrete to the most metaphorical, arguing that music ranged on the more metaphorical end of the spectrum above poetry. But I directed my attention towards the opposite pole, towards the more concrete. In analytic geometry, we are given equations for a line or a circle or an ellipse or whatever else. In reality, we are being given an extremely concrete description of each and every point of that curve or shape. IOW, algebra is itself a language that describes very concrete relationships -- of course, it also helped that I had taken a physical science course in which they demonstrated how we can start with one equation and make substitutions to arrive at other equations, and also how each factor in an equation is related to all the other factors.
Armed with that new knowledge, I redirected my attention to word problems -- at the same time, I was finding that I needed some of that math, so I did a lot of self-tuition. Here is the point I'm trying to pass on to you! The word problems were written in English, but we needed to convert that to algebra, to translate them to algebra. Translating something from one language to another? Yeah, that was something I knew how to do! Once I took that approach, I was suddenly able to set up with ease word problems that used to confound me. Word problems were now easy for me! Shortly thereafter, I took a test for the Navy that was almost entirely word problems and I scored so high on it that they waived the age requirements for me. All because of what Leonard Bernstein had taught me.
Which brings us right back to what I had been telling you before. How do you solve a problem in programming? Well, the first step is to figure out how you would solve it by hand, what the manual method would be. Once you have the manual method, automating it is usually very simple. Most of the work is coming up with the manual method, because that requires that you understand what you are trying to do. But once you have that, you have it made.
Rather than panic when faced with a programming problem, think of how you would do it by hand. That will help you get started.