C++ Exercises: Check whether the primitive values crossing the limits or not
C++ Basic: Exercise-6 with Solution
Write a program in C++ to check whether the primitive values crossing the limits or not.
Sample Solution:
C++ Code :
#include <iostream>
using namespace std;
int main()
{
cout << "\n\n Check whether the primitive values crossing the limits or not :\n";
cout << "--------------------------------------------------------------------\n";
char gender = 'F'; // char is single-quoted
bool isEmployed = true; // true(non-zero) or false(0)
unsigned short numOfsons = 2; // [0, 255]
short yearOfAppt = 2009; // [-32767, 32768]
unsigned int YearlyPackage = 1500000; // [0, 4294967295]
double height = 79.48; // With fractional part
float gpa = 4.69f; // Need suffix 'f' for float
long totalDrawan = 12047235L; // Suffix 'L' for long
long long balance = 995324987LL; // Need suffix 'LL' for long long int
cout << " The Gender is : " << gender << endl;
cout << " Is she married? : " << isEmployed << endl;
cout << " Number of sons she has : " << numOfsons << endl;
cout << " Year of her appointment : " << yearOfAppt << endl;
cout << " Salary for a year : " << YearlyPackage << endl;
cout << " Height is : " << height << endl;
cout << " GPA is " << gpa << endl;
cout << " Salary drawn upto : " << totalDrawan << endl;
cout << " Balance till : " << balance << endl;
return 0;
}
Sample Output:
Check whether the primitive values crossing the limits or not : -------------------------------------------------------------------- The Gender is : F Is she married? : 1 Number of sons she has : 2 Year of her appointment : 2009 Salary for a year : 1500000 Height is : 79.48 GPA is 4.69 Salary drawn upto : 12047235 Balance till : 995324987
Flowchart:
C++ Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a program in C++ to check the upper and lower limits of integer.
Next: Write a program in C++ to display various type or arithmetic operation using mixed data type.
What is the difficulty level of this exercise?