Classwork 3a - UMBC-CMSC104/General GitHub Wiki

Name the code you use for this project arithmetic.c.

For this assignment, you're to write a program that prompts the user for a integer number. After that, you're to display the following:

  • A statement as to whether the number is a positive, negative, or zero. (dependent on review)
  • The number with 5 added to it. Store this into a variable for later user.
  • The number divided by 2. This number should be output as a double.
  • Use the variable you stored for the number + 5 and multiply it by 3.

Example output:

Welcome to classwork 3a.  Please enter a number: 4

The number is positive!
4 + 5 = 9
4 / 2 = 2.00000
9 * 3 = 27

To compile it:

gcc arithmetic.c -o arithmetic

To test it after you've compiled it:

./arithmetic

To submit it:

submit cs104_wilson cw03a arithmetic.c

Notes

  • Use the >, <, and == operators to determine if the number is positive, negative, or zero.
  • Use a variable to store the results of each computation to make things easier for yourself!
  • Please reference the code here (classwork 3) and here (variables live demo).
  • Try an if statement that looks like this:

Code:

if(<condition>)
{
    ....
}
else if(<condition>)
{
    ....
}
else
{
    ....
}
⚠️ **GitHub.com Fallback** ⚠️