SEATWORK 1
Directions: Create a C++ program that follows the given program specifications, paste your source code
and the screenshot of the sample output in the space provided.
1. Write a program to check if the number is positive and how many digits the number has using if
statement. If the inputted number is zero or a negative number, it should display, “It is a non-
positive number”. The maximum digits of the number that can be entered by the user should be
four only.
Program
#include <iostream>
using namespace std;
int main () {
float num;
cout << "Enter number: ";
cin >> num;
if(num <= 9999 && num > 0){
cout << num << " is a positive number.";
}
else if (num <= 0 && num > -9999) {
cout << "It is a non-positive number.";
}
else {
cout << "The maximum digit of the number that can only be 4.";
}
return 0;
}
Sample Output
Note: Take screenshot of the output given that the input is a one-,two-,three-,four-digit number and a
non-positive number.
CCS0003-Computer Programming 1 Page 2 of
6
2. Write a program that allows the user to select an arithmetic operator to be applied to the two
floating numbers inputted by the user using a switch statement.
Sample Output:
Program
#include <iostream>
using namespace std;
int main()
{
char op;
float num1;
float num2;
float result;
std::cout << "Enter your operator either (+ - * /): ";
std::cin >> op;
std::cout << "Enter your first number: ";
std::cin >> num1;
std::cout << "Enter your second number: ";
std::cin >> num2;
switch (op){
case '+':
result = num1 + num2;
cout << "Result: " << result << '\n';
break;
case '-':
result = num1 - num2;
CCS0003-Computer Programming 1 Page 3 of
6
cout << "Result: " << result << '\n';
break;
case '*':
result = num1 * num2;
cout << "Result: " << result << '\n';
break;
case '/':
result = num1 / num2;
cout << "Result: " << result << '\n';
break;
default:
cout << "Please only enter one of the 4 math operators" << '\n';
return 0;
}
CCS0003-Computer Programming 1 Page 4 of
6
Sample Output
Note: Take screenshot of the output when choosing each of the operators in the option.
CCS0003-Computer Programming 1 Page 5 of
6
CCS0003-Computer Programming 1 Page 6 of
6