Twenty problems that read numbers, work something out and print it. They are in order of difficulty: the first ten are the core of the week, and the rest are for when those are done.
Before you write any code, read the problem's Input and Output sections and answer three questions:
- What comes in, and in what order? Declare a variable for each value, then
read them in that order with
cin >>. - What has to be worked out? Several of these are one line of arithmetic — the work is finding which line.
- What exactly goes out? Numbers on one line separated by a space? Each on
its own line? The space and the
"\n"are yours to print.
Tools that come up again and again here:
/and%as a pair: whole minutes and the seconds left over, whole boxes and the items left over.n % 10is the last digit ofn, andn / 10isnwithout it.- If an answer could pass 2 147 483 647, it needs a
long long— that is the next lesson, and a couple of these need it already.
And the rule that turns correct programs into Wrong Answers: no prompts.
Never print Enter a number or The answer is — only what the output section
asks for.