makan007 (37) Nov 21, 2009 at 7:29pm UTC
If the inputs are 4.5, 8.6 & 9.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
using namespace std;
int main()
{
int x,y;
float z;
cout << "Enter three numbers: " ;
cin >> x >> z >> y;
y = x + static_cast <int >(z);
x = static_cast <int >(z+1);
cout << x << "\t" << y << "\t" << z;
}
I need to know can I assume x = 4.5, y = 8.6 & z = 9?
hannes (59) Nov 21, 2009 at 7:29pm UTC
you declared x as an integer, then x can't be 4.5 and y can't be 8.6
makan007 (37) Nov 21, 2009 at 7:29pm UTC
I am actually asking... given the inputs are 4.5, 8.6 & 9 in qns. How do I know which input belongs to x, y & z?
hannes (59) Nov 21, 2009 at 7:29pm UTC
then you are assigning a double to an integer: you assign 4.5 to x, and x is an integer.
makan007 (37) Nov 21, 2009 at 7:29pm UTC
Anyone knows how to solve?
Zhuge (324) Nov 21, 2009 at 7:29pm UTC
Static casting a double to an int will truncate it. But as hannes says, how can x and y be 4.5 and 8.6 if they are ints?
makan007 (37) Nov 21, 2009 at 7:29pm UTC
If the inputs are x = 4.5, y =9 & z = 8.6...
Disch (1024) Nov 21, 2009 at 7:29pm UTC
EDIT - oh blah I just saw the other question.
Way to read, Disch.
nevermind.
Last edited on Nov 21, 2009 at 7:29pm UTC