// Lab5.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
//1) Ask the user for a whole numberand then tell the user if the number is even or not.
//e.g. 2 ==> Even
//11 == > Odd
//2) Ask the user for decimal numberand then tell the user what first number after the decimal point is.
//e.g. 2.1 ==> 1
//12345.34 == > 3
//3) Ask the user for a three digit whole numberand tell the user what the three digits are.
//e.g 123 ==> 1 2 3
//321 == > 3 2 1
//
//4) Enter a decimal numberand tell the user the whole number portionand the decimal portion of the number
//e.g 123.45 ==> 123 45
//123.6789 == > 123 6789
//
//5) Ask the user to enter a 3 digit whole number and make sure that it has exactly 3 digits
#include
using namespace std;
int main()
{
// q1
cout << "Enter a whole number and I will tell you if it is even or odd"
<< endl;
int i;
cin >> i;
if (i % 2 == 0)
cout << "number is even" << endl;
else
cout << "number is odd" << endl;
// q2
cout << "Enter a decimal number and I will tell you the first digit"
<< " after the decimal" << endl;
double d;
cin >> d;
d = d * 10; // shift the digit after the decimal
int b = d; // truncated all the decimal portion
cout << b % 10 << endl; // when we divide by 10 and
//take the remainder we will get the last digit
//q3
cout << "enter a three digit whole number and I will give you " <<
"the individual digits" << endl;
cin >> i;
int last_digit = i % 10;
i = i / 10;
int middle_digit = i % 10;
i = i / 10;
int first_digit = i;
cout << first_digit << " " << middle_digit << " " << last_digit;
//q4
cout << "Enter a decimal number and I will tell you the whole number portion "
<< " and the decimal portion of the number"
<< endl;
cin >> d;
int whole_number_portion = d;//strips off the decimal part
double decimal_portion = d - whole_number_portion;
cout << " For " << d << "whole number = " << whole_number_portion
<< " decimal portion =" << decimal_portion << endl;
// q5
cout << "Enter only a three digit whole number" << endl;
cin >> i;
if (i < 100)
cout << "you didn't enter enough digits" << endl;
else if (i > 999)
cout << "you entered too many digits" << endl;
else
cout << "you entered correct amount of digits" << endl;
return(0);
}