This lab introduces students to working with floating-point and integer data types by combining user input, arithmetic operations, and formatted output. Students will write a program that takes two numbers as floating-point inputs, performs arithmetic operations (addition, subtraction, multiplication, division) using floating-point calculations, and then converts the inputs to integers to demonstrate integer division. This lab emphasizes the differences between floating-point and integer arithmetic, reinforcing key programming concepts that are fundamental for understanding data types and numerical operations in programming.
This lab consists of the following tasks:
Prompting for and Reading User Input:
Performing Floating-Point Arithmetic:
Demonstrating Integer Division:
Displaying Results:
Create variables to store two user-provided floating-point numbers.
Use input/output statements to prompt the user and read their numbers.
Perform floating-point arithmetic (addition, subtraction, multiplication, division) and store the results.
Convert the floating-point inputs to integers.
Perform integer division and modulus operations using the integer values and store the results.
Display the results of all operations (floating-point and integer) with descriptive and formatted messages.
To successfully complete this lab, follow the checklist below:
User Input:
Floating-Point Arithmetic:
Integer Conversion and Operations:
Output Results:
Code Quality:
Submission:
Enter the first number (floating-point): 12.7 Enter the second number (floating-point): 3.4 Floating-point results: Sum: 16.1 Difference: 9.3 Product: 43.18 Quotient: 3.73529 Integer results (using truncated values): Integer Division Quotient: 3 Modulus: 0
Save: Save your program as main.cpp
. Do not ignore this step or save the file with different names. If CANVAS adds a -# to the file name it is because CANVAS saves all submissions, this is normal.
Submit: You have until 11:59p on the due date to complete this lab. There will be no extensions for any reason. Your program must be submitted before the due day/time via the submission link(s) on CANVAS. No emailed submissions will be accepted.