Input and Variable problems

The following contains extra input and variable related problems. Try them out.

Problem 1:

What is the best data type to store each of the values below?

  1. The number of people living in Canada

  2. pi to 2 decimal places

  3. The answer to a multiple choice question where the choices are A,B,C or D

  4. pi to 10 decimal places

  5. Number of muffins sold

  6. Taxes due on a bottle of pop

Problem 2:

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

Problem 3:

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:

Please enter a decimal number: 123.456
the part before the decimal is 123
the part after the decimal is 456

*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.

Problem 4:

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:

Please enter a lower case alphabetic character: d
d is letter number 4 in the alphabet.

Last updated