i need to find the user I/p is an String or char or int or float
in C++ lang .

My Goal
is to Get 3 inputs from user
and Find the Greatest of all
and list out it
but matter of fact the Big deal is
the INPUT may be int or may be float or char
1st i need figurout the data struct of input and the find greatest .

This is my point,
Any Suggestions codes .

Recommended Answers

All 11 Replies

Any One Help ..... please......

Input to a string, then call a function to check whether it the input string has only digits (and '.', '+' and '-' as first only). If it really has only digits, it's a number. If it has a dot, it's a floating-point number, else it's an integer.
If you reach a character that isn't one of the above, it's simply a string. Furthermore, if the string only has one character, it's a char.

After determining what's the user input, you can use the atoi (ASCII to int) or atof (ASCII to float) to convert the string to a number (if the input is a number, of course)

Can U Povide some part of codes
plz unbeatable0

#include<iostream>
#include<string>

using namespace std;

#define IS_STRING 1
#define IS_CHARACTER 2
#define IS_INTEGER 3
#define IS_FLOAT 4

int main(void)
{
string Input;
cout<<"Input a string/character/number:\n";
cin>>Input;
short int input_type=0;
int x;
bool DotReached=false;
if(Input.length()==1 && (Input[0]>'9' || Input[0]<'0'))
input_type=IS_CHARACTER;
else
  for(x=0;x<Input.length();x++)
  {
  if((Input[x]>'9' || Input[x]<'0') && Input[x]!='.') 
     {input_type=IS_STRING; break;}
   else if(Input[x]=='.')
     {if(!DotReached) DotReached=ture; else
        {input_type=IS_STRING; break;}
     }
  }
// continue from here
}
commented: Good , wat i needed is Got exactly ........ +1

any one plz Explain these above code ??????
pllzzzzz .....

include<iostream>
include<string>

using namespace std;

define IS_STRING 1
define IS_CHARACTER 2
define IS_INTEGER 3
define IS_FLOAT 4

int main(void)
{
string Input;
cout<<"Input a string/character/number:\n";
cin>>Input;
short int input_type=0;
int x;
bool DotReached=false;
if(Input.length()==1 && (Input[0]>'9' || Input[0]<'0'))
input_type=IS_CHARACTER;
else
for(x=0;x<Input.length();x++)
{
if((Input[x]>'9' || Input[x]<'0') && Input[x]!='.')
{input_type=IS_STRING; break;}
else if(Input[x]=='.')
{if(!DotReached) DotReached=ture; else
{input_type=IS_STRING; break;}
}
}

please use code tags, and avoid red text many people will be repelled by it!

define IS_STRING 1
define IS_CHARACTER 2
define IS_INTEGER 3
define IS_FLOAT 4

This is to make a it easy for you to understand, basically writing IS_STRING is exactly the same as writing 1.

bool DotReached=false;

Create a boolean value can have the value of true or false

if(Input.length()==1 && (Input[0]>'9' || Input[0]<'0'))

Checks to see if the input is only one char long, if so checks thats its bewteen 0 and 9. Otherwise it must be a Char, cannot be a floating point. If it is between 0 and 9 then it is a integer.

if((Input[x]>'9' || Input[x]<'0') && Input[x]!='.')
{input_type=IS_STRING; break;}

Checks to see if the character is between 0-9 or is a '.' if not then its a string and breaks the loop since we have no reason to carry on.

{if(!DotReached) DotReached=ture; else
{input_type=IS_STRING; break;}

Checks to see if Dotreached has been set, if it has and we are at this point again then we know its a string. If it hasn't then it could still be a floating point.

Chris

commented: Thk Yu Chris........U r Kind Enough to teach me.......I m Happy ....... +1

THank You Chrisssssss...............

Plz Give me A good C++ compiler.........
links to download it

Okay SIr
I GOT IT

FIANLLY PROBLEM SOLVED.........

THANKS TO ALL .................

See if you are planning to give the arguements through command line then this could be the foloowing steps you can do;
(1) Check the number of arguements first.
(2) Check whether the argument values are NON Null
(3) Check the type of the data whether it is is string, integer or float.

i will give you the code shortly if you need!!!
Command line parsing would be much more easier and generic!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.