Input and Variable problem solutions
STOP! Before you look here, make sure you have completed your attempt at the problem
Question
The number of people living in Canada:
int
pi to 2 decimal places:
float
The answer to a multiple choice question where the choices are A,B,C or D:
char
pi to 10 decimal places:
double
Number of muffins sold:
int
Taxes due on a bottle of pop:
float
Solution:
Number of people living in Canada is under 2 billion and its a whole number. So, int works.
pi to 2 decimal is 3.14. A float is enough to store this. A double can also store it but it is more storage than needed for this amount of precision
A, B, C and D are all characters. so char works here
pi to 10 decimal places need more storage than a float can handle, need double for more precision
Unless you are selling more than 2 billion muffins, int is enough.
The amount of taxes due on a bottle of pop should not have more than 3 to 4 significant digits so a float is good enough.
Question
Write a program that will ask the user to enter the length and width dimensions of a room in meters. Program will then calculate the area of the room (assuming it is rectangular). Remember area is calculated as length*width
Solution
Question
Write a program that will ask the user to enter a decimal number. It will then print out the part of the number before the decimal point and after the decimal point separately.
For example, suppose the user enters 123.456. The program will print out:
the part before the decimal is 123 the part after the decimal is 456
Sample run:
*Note - A sample run is used to provide inside on what you should see when your program runs. You should use it as a guide. It may also serve to clarify the problem.
Solution
Question
Write a program that will ask the user to enter an lower case alphabetic character. The program will then tell them what letter of the alphabet it is.
For example, if the user enters the letter a, the program will say that it is letter number 1. Thus, b would be letter number 2, c would be letter number 3 and so on.
Sample run:
Solution
Last updated