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?

//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.

Recommended Answers

All 7 Replies

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 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.

Thnxfor big question.Do u have anything Teasing..Do post it in here... :)

Teasing questions right.
What is the output of this.

#include<stdio.h>

int main ()
{
printf ( "%f", 10 ) ;
return 0 ;
}

That was teasing one...it prints 0.00000 on my console......
can u explain why? and next teasing code guys,,,keep then coming...

Give your mind a thought first.

i got it regarding the Format specifier..Hehe...Next question...Lets start with something teasy with strings... :)

#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.

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.