MAX and MIN values of CHAR could not be displayed. Why ?
BTW, any advice on improvement ?
(please remember i have covered chapter 4 only)
------------- PROGRAMME --------------
/* Stroustrup 3e, section 4.11, exercise 5
STATEMENT:
what, on your system, are the largest and smallest values of the
following types:
char, short, int, long, float, double, long double and unsigned.
*/
#include<iostream>
#include<limits>
int main()
{
std::cout << "Largest float == " <<
std::numeric_limits<float>::max() << '\n';
std::cout << "Smallest float == " <<
std::numeric_limits<float>::min() << '\n';
std::cout << "Largest double == " <<
std::numeric_limits<double>::max() << '\n';
std::cout << "Smallest double == " <<
std::numeric_limits<double>::min() << '\n';
std::cout << "Largest long double == " <<
std::numeric_limits<long double>::max() << '\n';
std::cout << "smallest long double == " <<
std::numeric_limits<long double>::min() << '\n';
std::cout << '\n';
std::cout << "Largest char == " <<
std::numeric_limits<char>::max() << '\n';
std::cout << "Smallest char == " <<
std::numeric_limits<char>::min() << '\n';
std::cout << "Largest int == " <<
std::numeric_limits<int>::max() << '\n';
std::cout << "Smallest int == " <<
std::numeric_limits<int>::min() << '\n';
std::cout << "Largest short == " <<
std::numeric_limits<short>::max() << '\n';
std::cout << "Smallest short == " <<
std::numeric_limits<short>::min() << '\n';
std::cout << '\n';
std::cout << "Largest Unsigned (int) == " <<
std::numeric_limits<unsigned>::max() << '\n';
std::cout << "Smallest Unsigned (int) == " <<
std::numeric_limits<unsigned>::min() << '\n';
std::cout << "Largest Long (int) == " <<
std::numeric_limits<long>::max() << '\n';
std::cout << "Smallest Long (int) == " <<
std::numeric_limits<long>::min() << '\n';
return 0;
}
------------- OUTPUT -------------
[arch@voodo tc++pl]$ g++ -pedantic -ansi -Wall -Wextra 4.11_5.cpp
[arch@voodo tc++pl]$ ./a.out
Largest float == 3.40282e+38
Smallest float == 1.17549e-38
Largest double == 1.79769e+308
Smallest double == 2.22507e-308
Largest long double == 1.18973e+4932
smallest long double == 3.3621e-4932
Largest char ==
Smallest char == ?
Largest int == 2147483647
Smallest int == -2147483648
Largest short == 32767
Smallest short == -32768
Largest Unsigned (int) == 4294967295
Smallest Unsigned (int) == 0
Largest Long (int) == 2147483647
Smallest Long (int) == -2147483648
[arch@voodo tc++pl]$ 2 5317
* arnuld:
MAX and MIN values of CHAR could not be displayed. Why ?
std::cout interprets those values as characters, because the type is 'char'.
To have them displayed as numbers, just add 0 to force a promotion to 'int'.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
On Mar 26, 3:53 pm, "Alf P. Steinbach" <a...@start.nowrote:
std::cout interprets those values as characters, because the type is 'char'.
To have them displayed as numbers, just add 0 to force a promotion to 'int'.
cool... 8-) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Oplec |
last post by:
Hi,
I am learning standard C++ as a hobby. The C++ Programming Language :
Special Edition has been the principal source for my information. I read the
entirety of the book and concluded that I...
|
by: arnuld |
last post by:
problem: define functions F(char), g(char&) & h(const char&). call
them with arguments 'a', 49, 3300, c, uc & sc where c is a char, uc is
unsigned char & sc is signed char. whihc calls are legal?...
|
by: arnuld |
last post by:
Stroustrup has a table in section 4.9 of declarations and
definitions. he asks to write a similar table but in opposite sense:
char ch; // declaration with definition
he asks to do the...
|
by: arnuld |
last post by:
this programme runs without any trouble. it took 45 minutes of typing.
i posted it here so that people can save their precious time:
// Stroustrup special edition
// chapter 4 exercise 2
//...
|
by: arnuld |
last post by:
i did what i could do at Best to solve this exercise and this i what i
have come up with:
----------- PROGRAMME --------------
/* Stroustrup 5.9, exercise 3
STATEMENT:
Use typedef to define...
|
by: arnuld |
last post by:
/* Stroustrup: 5.9 exercise 7
STATEMENTS:
Define a table of the name sof months o fyear and the number of days
in each month. write out that table. Do this twice:
1.) using ar array of char...
|
by: arnuld |
last post by:
this one was much easier and works fine. as usual, i put code here for
any further comments/views/advice:
--------- PROGRAMME ------------
/* Stroustrup: 5.9 exercise 7
STATEMENTS:
Define a...
|
by: arnuld |
last post by:
there is no "compile-time error". after i enter input and hit ENTER i
get a run-time error. here is the code:
---------- PROGRAMME --------------
/* Stroustrup, 5.9, exercise
11
STATEMENT:...
|
by: arnuld |
last post by:
it works fine without any trouble. i want to have advice on improving
the code from any angle like readability, maintenance etc:
---------- PROGRAMME ------------
/* Stroustrup, 5.9, exercise 11...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |