| | |
How To Get this ??
Thread Solved
![]() |
I have problem in getting outputs
plz give me suggetion or correct error if any and make it working.......
plz help.........
there is no error........in this program.........when i compiled.
plz give me suggetion or correct error if any and make it working.......
plz help.........
there is no error........in this program.........when i compiled.
c++ Syntax (Toggle Plain Text)
#include<iostream> #include<cstdio> #include<cstring> #include<cstdio> #define IS_STRING 1 #define IS_CHARACTER 2 #define IS_INTEGER 3 #define IS_FLOAT 4 //using std::cout; //using std::cin; //using std::endl; using namespace std; int main(void) { string s; cout<<"Input a string/character/number:\n"; cin>>s; short int input_type=0; int x; bool DotReached=false; if(s.length()==1 && (s[0]>'9' || s[0]<'0')) { input_type=IS_CHARACTER; cout<< "its a char"; } else for(x=0;x<s.length();x++) { if((s[x]>'9' || s[x]<'0') && s[x]!='.') { input_type=IS_STRING; break; cout<<" Its an integer "; } else if(s[x]=='.') {if(!DotReached) DotReached= true; else { input_type=IS_STRING; cout<<"ITs a Float"; break; } } } cin.get(); cin.get(); return 0; }
Last edited by ninja_gs; Dec 16th, 2008 at 9:43 am.
" Known is A Drop - Unknown is An Ocean "
•
•
Join Date: Sep 2008
Posts: 90
Reputation:
Solved Threads: 12
c++ Syntax (Toggle Plain Text)
for(x=0;x<s.length();x++) { if((s[x]>'9' || s[x]<'0') && s[x]!='.') { input_type=IS_STRING; break; cout<<" Its an integer "; } else if(s[x]=='.') { if(!DotReached) DotReached= true; else { input_type=IS_STRING; cout<<"ITs a Float"; break; } } }
Line 6:
How do you want the program to output "It's an integer" when there's a "break;" before it?
You should output "It's a string" and not "It's an integer" if the input_type is IS_STRING.
Line 14:
Again, it's a string, not a floating-point number.
If you want to determine the input type after you know it's not a char/string (if input_type==0, which is its initial value), you should just check if DotReached returns true or false, because you already know it's a number:
c++ Syntax (Toggle Plain Text)
if(input_type==0) // the initial value - meaning no type is determined yet { if(DotReached) input_type=IS_FLOAT; else input_type=IS_INTEGER; }
Last edited by unbeatable0; Dec 16th, 2008 at 10:30 am.
Cool i corrected it ......
thanks Mr Unbeatable()
It works but Also Say Its integer
when i enter Floating
Need help for this Part
Wats wrong ??
it shows Int For float.............
thanks Mr Unbeatable()
It works but Also Say Its integer
when i enter Floating
C++ Syntax (Toggle Plain Text)
#include<iostream> #include<cstdio> #include<cstring> #include<cstdio> #define IS_STRING 1 #define IS_CHARACTER 2 #define IS_INTEGER 3 #define IS_FLOAT 4 //using std::cout; //using std::cin; //using std::endl; using namespace std; int main(void) { string s; cout<<"Input a string/character/number:\n"; cin>>s; short int input_type=0; int x; bool DotReached=false; if(s.length()==1 && (s[0]>'9' || s[0]<'0')) { input_type=IS_CHARACTER; cout<< "its a char"; } else for(x=0;x<s.length();x++) { if((s[x]>'9' || s[x]<'0') && s[x]!='.') { input_type=IS_STRING; cout<<" ITs an String "; break; } else if(input_type==0) { if(DotReached) { input_type=IS_FLOAT; cout<<"Its a Floating Point Value"; break; } else { input_type=IS_INTEGER; cout<<"Its an Integer"; break; } } } cin.get(); cin.get(); cin.get(); return 0; }
Need help for this Part
Wats wrong ??
it shows Int For float.............
Last edited by ninja_gs; Dec 16th, 2008 at 12:04 pm.
" Known is A Drop - Unknown is An Ocean "
•
•
Join Date: Sep 2008
Posts: 90
Reputation:
Solved Threads: 12
You have a few errors:
Firstly, the
Therefore you need to end the loop before this 'if' and remove the 'else' before it.
Secondly, in lines 38-39, the type is IS_STRING, because a number can't have more than a single dot.
Now just return the code you've put in the comments. It's necessary!
Lastly, you don't need the
Firstly, the
if(input_value==0) ..... should be OUTSIDE the 'for' loop, because you want to check what kind of number the input is after you know it isn't a string nor a char.Therefore you need to end the loop before this 'if' and remove the 'else' before it.
Secondly, in lines 38-39, the type is IS_STRING, because a number can't have more than a single dot.
Now just return the code you've put in the comments. It's necessary!
Lastly, you don't need the
break; in lines 49 and 55, as they're not supposed to be in a loop Last edited by unbeatable0; Dec 16th, 2008 at 11:50 am.
I think i corrected mistakes you have mentioned earlier........
Plz Now Say wats the Problem.........
Plz Now Say wats the Problem.........
c++ Syntax (Toggle Plain Text)
#include<iostream> #include<cstdio> #include<cstring> #include<cstdio> #define IS_STRING 1 #define IS_CHARACTER 2 #define IS_INTEGER 3 #define IS_FLOAT 4 //using std::cout; //using std::cin; //using std::endl; using namespace std; int main(void) { string s; cout<<"Input a string/character/number:\n"; cin>>s; short int input_type=0; int x; bool DotReached=false; if(s.length()==1 && (s[0]>'9' || s[0]<'0')) { input_type=IS_CHARACTER; cout<< "its a char"; } else for(x=0;x<s.length();x++) { if((s[x]>'9' || s[x]<'0') && s[x]!='.') { input_type=IS_STRING; cout<<" ITs an String "; break; } } //else if(input_type==0) { if(DotReached) { input_type=IS_FLOAT; cout<<"Its a Floating Point Value"; //break; } else { input_type=IS_INTEGER; cout<<"Its an Integer"; //break; } } cin.get(); cin.get(); cin.get(); return 0; }
Last edited by ninja_gs; Dec 16th, 2008 at 12:10 pm.
" Known is A Drop - Unknown is An Ocean "
•
•
Join Date: Sep 2008
Posts: 90
Reputation:
Solved Threads: 12
That's because you removed this piece of code from your code:
c++ Syntax (Toggle Plain Text)
else if(s[x]=='.') { if(!DotReached) DotReached= true; else { input_type=IS_FLOAT; cout<<"ITs a Float"; break; } }
Last edited by unbeatable0; Dec 16th, 2008 at 12:14 pm.
c++ Syntax (Toggle Plain Text)
#include<iostream> #include<cstdio> #include<cstring> #include<cstdio> #define IS_STRING 1 #define IS_CHARACTER 2 #define IS_INTEGER 3 #define IS_FLOAT 4 //using std::cout; //using std::cin; //using std::endl; using namespace std; int main(void) { string s; cout<<"Input a string/character/number:\n"; cin>>s; short int input_type=0; int x; bool DotReached=false; if(s.length()==1 && (s[0]>'9' || s[0]<'0')) { input_type=IS_CHARACTER; cout<< "its a char"; } else for(x=0;x<s.length();x++) { if((s[x]>'9' || s[x]<'0') && s[x]!='.') { input_type=IS_STRING; cout<<" ITs an String "; break; } else if(s[x]=='.') { if(!DotReached) DotReached= true; else { input_type=IS_FLOAT; cout<<"Its a flt"; break; } //else if(input_type==0) // the initial value - meaning no type is determined yet { if(DotReached) { input_type=IS_FLOAT; cout<<"Its a Floating Point Value"; //break; } else { input_type=IS_INTEGER; cout<<"Its an Integer"; //break; } } cin.get(); cin.get(); cin.get(); return 0; } } }
IS THIS SO ?????/
MENTION THE LINE IN HERE SIR
I CANT GET IT ....SIR
CAN YOU PLZ FILL WAT TO BE ADDED ........
PLZ.........
Last edited by ninja_gs; Dec 16th, 2008 at 12:46 pm.
" Known is A Drop - Unknown is An Ocean "
•
•
•
•
COOL IT WORKS
I GOTTCHA
THNKS MAN
UR A KIND FULL PERSON MAN
NOW I AM HAPPY
Great job..........Mr.Unbeatable()..........
heres the working Code
c++ Syntax (Toggle Plain Text)
#include<iostream> #include<cstdio> #include<cstring> #include<cstdio> #define IS_STRING 1 #define IS_CHARACTER 2 #define IS_INTEGER 3 #define IS_FLOAT 4 //using std::cout; //using std::cin; //using std::endl; using namespace std; int main(void) { string s; cout<<"Input a string/character/number:\n"; cin>>s; short int input_type=0; int x; bool DotReached=false; if(s.length()==1 && (s[0]>'9' || s[0]<'0')) { input_type=IS_CHARACTER; cout<< "its a char"; } else for(x=0;x<s.length();x++) { if((s[x]>'9' || s[x]<'0') && s[x]!='.') { input_type=IS_STRING; cout<<" ITs an String "; break; } else if(s[x]=='.') { if(!DotReached) { DotReached= true; } else { input_type=IS_STRING; cout<<"Its a flt"; break; } } } //else if(input_type==0) // the initial value - meaning no type is determined yet { if(DotReached) { input_type=IS_FLOAT; cout<<"Its a Floating Point Value"; //break; } else { input_type=IS_INTEGER; cout<<"Its an Integer"; //break; } } cin.get(); cin.get(); cin.get(); return 0; }
" Known is A Drop - Unknown is An Ocean "
![]() |
Other Threads in the C++ Forum
- Previous Thread: Debug Assertion failed. help?
- Next Thread: ideas to setting my array to all zeros
| Thread Tools | Search this Thread |
action api array auto based beginner binary bitmap c++ c/c++ calculator challenge char class classes code coding compile console conversion count createcopyofanyfileinc delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game garbage givemetehcodez graph gui hmenu homeworkhelp homeworkhelper iamthwee ifstream input insert int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node noob output parameter pointer primenumbersinrange problem program programming project python random read recursion reference rpg sockets string strings temperature template test text text-file tree url variable vector video win32 windows winsock wordfrequency wxwidgets





