help

i am trying to make a a small program get from the user the type and print the data of the type like it range and how many bytes....

#include <iostream> // std::cout
#include <limits> // std::numeric_limits
#include<cstdlib>
#include<string>
using namespace std;
void print_value(string * value,string input1);
int main()
{
string array1[14] = { "bool", "char", "signed char", "unsigned char", "wchar_t", "short", "unsigned short","int", "unsigned int", "long", "unsigned long", "float", "double", "long double" };
string * p2;
string input;
p2 =array1;

cout << " please enter the type you want to know about :" << endl;
getline(cin,input);

print_value(p2, input);
system("pause");
return 0;
}

void print_value(string *value,string input1)
{
int i=0, j=0;
string arr[5] = { "Minimum value for ", "Maximum value for ", " is signed ", "Non-sign bits in ", "the size of " };
string c = " : ";
switch (i)
{
case 0:
if (*value == input1)//bool
{
cout << arr[j++]<<*value<<c<< numeric_limits<bool>::min() << '\n';
cout << arr[j++] << *value<<c << numeric_limits<bool>::max() << '\n';
cout << *value << arr[j++] << c << numeric_limits<bool>::is_signed << '\n';
cout << arr[j++] <<*value <<c << numeric_limits<bool>::digits << '\n';
cout << arr[j++] << *value <<c << sizeof(bool) << " bytes" << endl;
break;
}
else
{
i++;
value += 1;
}
case 1:
if (*value == input1)//char
{
cout << arr[j++] << *value << c<<(int)numeric_limits<char>::min() << '\n';
cout << arr[j++] << *value << c << (int)numeric_limits<char>::max() << '\n';
cout << *value << arr[j++] <<c<< numeric_limits<char>::is_signed << '\n';
cout << arr[j++] << *value << c << numeric_limits<char>::digits << '\n';
cout << arr[j++] << *value << c << sizeof(char) <<" btyes"<< endl;
break;
}
else
{
i++;
value += 1;
}
case 2:
if (*value == input1)//sign char
{
cout << arr[j++] << *value << c << (int)numeric_limits<signed char>::min() << '\n';
cout << arr[j++] << *value << c << (int)numeric_limits<signed char>::max() << '\n';
cout << *value << arr[j++] << c << (int)numeric_limits<signed char>::is_signed << '\n';
cout << arr[j++] << *value << c << (int)numeric_limits<signed char>::digits << '\n';
cout << arr[j++] << *value << c << sizeof(signed char) << " bytes" << endl;
break;
}
else
{
i++;
value += 1;
}
case 3:
if (*value == input1)//unsigned char
{
cout << arr[j++] << *value << c << (int)numeric_limits<unsigned char>::min() << '\n';
cout << arr[j++] << *value << c << (int)numeric_limits<unsigned char>::max() << '\n';
cout << *value << arr[j++] << c << (int)numeric_limits<unsigned char>::is_signed << '\n';
cout << arr[j++] << *value << c << (int)numeric_limits<unsigned char>::digits << '\n';
cout << arr[j++] << *value << c << sizeof(unsigned char) << " bytes" << endl;
break;
}
else
{
i++;
value += 1;
}
case 4:
if (*value == input1)//wchar_t
{
cout << arr[j++] << *value << c << numeric_limits<wchar_t>::min() << '\n';
cout << arr[j++] << *value << c << numeric_limits<wchar_t>::max() << '\n';
cout << *value << arr[j++] << c << numeric_limits<wchar_t>::is_signed << '\n';
cout << arr[j++] << *value << c << numeric_limits<wchar_t>::digits << '\n';
cout << arr[j++] << *value << c << sizeof(wchar_t) << " bytes" << endl;
break;
}
else
{
i++;
value += 1;
}
case 5:
if (*value == input1)//short
{
cout << arr[j++] << *value << c << numeric_limits<short>::min() << '\n';
cout << arr[j++] << *value << c << numeric_limits<short>::max() << '\n';
cout << *value << arr[j++] << c << numeric_limits<short>::is_signed << '\n';
cout << arr[j++] << *value << c << numeric_limits<short>::digits << '\n';
cout << arr[j++] << *value << c << sizeof(short) << " bytes" << endl;
break;
}
else
{
i++;
value += 1;
}
case 6:
if (*value == input1)//unsigned short
{
cout << arr[j++] << *value << c << numeric_limits<unsigned short>::min() << '\n';
cout << arr[j++] << *value << c << numeric_limits<unsigned short>::max() << '\n';
cout << *value << arr[j++] << c << numeric_limits<unsigned short>::is_signed << '\n';
cout << arr[j++] << *value << c << numeric_limits<unsigned short>::digits << '\n';
cout << arr[j++] << *value << c << sizeof(unsigned short) << " bytes" << endl;
break;
}
else
{
i++;
value += 1;
}
case 7:
if (*value == input1)//int
{
cout << arr[j++] << *value << c << numeric_limits<int>::min() << '\n';
cout << arr[j++] << *value << c << numeric_limits<int>::max() << '\n';
cout << *value << arr[j++] << c << numeric_limits<int>::is_signed << '\n';
cout << arr[j++] << *value << c << numeric_limits<int>::digits << '\n';
cout << arr[j++] << *value << c << sizeof(int) << " bytes" << endl;
break;
}
else
{
i++;
value += 1;
}
case 8:
if (*value == input1)//unsigned int
{
cout << arr[j++] << *value << c << numeric_limits<unsigned int>::min() << '\n';
cout << arr[j++] << *value << c << numeric_limits<unsigned int>::max() << '\n';
cout << *value << arr[j++] << c << numeric_limits<unsigned int>::is_signed << '\n';
cout << arr[j++] << *value << c << numeric_limits<unsigned int>::digits << '\n';
cout << arr[j++] << *value << c << sizeof(unsigned int) << " bytes" << endl;
break;
}
else
{
i++;
value += 1;
}
case 9:
if (*value == input1)//long
{
cout << arr[j++] << *value << c << numeric_limits<long>::min() << '\n';
cout << arr[j++] << *value << c << numeric_limits<long>::max() << '\n';
cout << *value << arr[j++] << c << numeric_limits<long>::is_signed << '\n';
cout << arr[j++] << *value << c << numeric_limits<long>::digits << '\n';
cout << arr[j++] << *value << c << sizeof(long) << " bytes" << endl;
break;
}
else
{
i++;
value += 1;
}
case 10:
if (*value == input1)//unsiged long
{
cout << arr[j++] << *value << c << numeric_limits<unsigned long>::min() << '\n';
cout << arr[j++] << *value << c << numeric_limits<unsigned long>::max() << '\n';
cout << *value << arr[j++] << c << numeric_limits<unsigned long>::is_signed << '\n';
cout << arr[j++] << *value << c << numeric_limits<unsigned long>::digits << '\n';
cout << arr[j++] << *value << c << sizeof(unsigned long) << " bytes" << endl;
break;
}
else
{
i++;
value += 1;
}
case 11:
if (*value == input1)//float
{
cout << arr[j++] << *value << c << numeric_limits<float>::min() << '\n';
cout << arr[j++] << *value << c << numeric_limits<float>::max() << '\n';
cout << *value << arr[j++] << c << numeric_limits<float>::is_signed << '\n';
cout << arr[j++] << *value << c << numeric_limits<float>::digits << '\n';
cout << arr[j++] << *value << c << sizeof(float) << " bytes" << endl;
break;
}
else
{
i++;
value += 1;
}
case 12:
if (*value == input1)//double
{
cout << arr[j++] << *value << c << numeric_limits<double>::min() << '\n';
cout << arr[j++] << *value << c << numeric_limits<double>::max() << '\n';
cout << *value << arr[j++] << c << numeric_limits<double>::is_signed << '\n';
cout << arr[j++] << *value << c << numeric_limits<double>::digits << '\n';
cout << arr[j++] << *value << c << sizeof(double) << " bytes" << endl;
break;
}
else
{
i++;
value += 1;
}
case 13:
if (*value == input1)//long double
{
cout << arr[j++] << *value << c << numeric_limits<long double>::min() << '\n';
cout << arr[j++] << *value << c << numeric_limits<long double>::max() << '\n';
cout << *value << arr[j++] << c << numeric_limits<long double>::is_signed << '\n';
cout << arr[j++] << *value << c << numeric_limits<long double>::digits << '\n';
cout << arr[j++] << *value << c << sizeof(long double) << " bytes" << endl;
break;
}
default:
cout << "Invalid type plesse check the spelling and try again \n";
}
}

my q? is:
i write the code"
numeric_limits<bool>::min()
is there a way to write variable instead type(bool)
because we get a string from the user and than i want to convert the string to type
numeric_limits<variable>::min()
this variable reference to type(int or char or bool...)
in this way i can write a function to print details .
it's possible to do this functions
thank's
best regard
Last edited on
Topic archived. No new replies allowed.