| | |
Brainteaser codes
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2007
Posts: 44
Reputation:
Solved Threads: 0
It's not homework it is just a play.If you have any simmilar tragic like this one with int and character or float then please discuss it here or explain how things happen.Let this thread be informative.
I'm playing with int,floats and type casts but i have found that in following program when i enter the value of first integer as float,it skips out the cout statement that asks for float value,instead it takes the float value frm the decimal number we entered frm the first first input we get from cin.What is going on? i dnt get it if i entered float value then it skips next statement?How and why?How can i get my chance of inputing another float number in that case? Anyone like to explain what happened here?
I have one more Big Question in this case is that "If i want to find out what value is input by user here,before printing it.How can i find out that it's integer or float?"
You can pass your teasing questions here or answer mine,i'm looking for simmilar situations with the code.
I'm playing with int,floats and type casts but i have found that in following program when i enter the value of first integer as float,it skips out the cout statement that asks for float value,instead it takes the float value frm the decimal number we entered frm the first first input we get from cin.What is going on? i dnt get it if i entered float value then it skips next statement?How and why?How can i get my chance of inputing another float number in that case? Anyone like to explain what happened here?
C++ Syntax (Toggle Plain Text)
//IDE: Codeblocks 8.02 #include<iostream> using namespace std; int main() { int a; float b; cout<<"Enter the integer number"<<endl; cin>>a; cout<<"\n Enter float number"<<endl; cin>>b; cout<<endl; cout<<a<<endl; cout<<b<<endl; system("pause"); exit(0); }
I have one more Big Question in this case is that "If i want to find out what value is input by user here,before printing it.How can i find out that it's integer or float?"
You can pass your teasing questions here or answer mine,i'm looking for simmilar situations with the code.
•
•
Join Date: Jun 2007
Posts: 275
Reputation:
Solved Threads: 45
You could store the user input in a string (instead of int or float), then check it for '.' character. If it has '.' then it's a float. Then use the string with a stringstream to put the number into float or int varable as desired.
•
•
Join Date: Jun 2007
Posts: 275
Reputation:
Solved Threads: 45
CPP Syntax (Toggle Plain Text)
#include <iostream> #define ENIUQ(TEMPLATE) std::cout << TEMPLATE << "(" << #TEMPLATE << ");}"; int main() {ENIUQ("#include <iostream>\n#define ENIUQ(TEMPLATE) std::cout << TEMPLATE << \"(\" << #TEMPLATE << \");}\";\n\nint main()\n{ENIUQ");}
Here's one for you.
![]() |
Similar Threads
- explorer.exe uses 99% CPU (Viruses, Spyware and other Nasties)
Other Threads in the C++ Forum
- Previous Thread: i need someone to explain how this works...
- Next Thread: cash register help..!!
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





