C++ Exercises: Check whether the primitive values crossing the limits or not
C++ Basic: Exercise-6 with Solution
Write a C++ program that checks whether primitive values cross the limit.
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?
C++ Programming: Tips of the Day
Why is there no std::stou?
The most pat answer would be that the C library has no corresponding "strtou", and the C++11 string functions are all just thinly veiled wrappers around the C library functions: The std::sto* functions mirror strto*, and the std::to_string functions use sprintf.
Ref: https://bit.ly/3wtz2qA
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook