Static Casting

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?

you declared x as an integer, then x can't be 4.5 and y can't be 8.6
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?
then you are assigning a double to an integer: you assign 4.5 to x, and x is an integer.
Anyone knows how to solve?
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?
If the inputs are x = 4.5, y =9 & z = 8.6...
EDIT - oh blah I just saw the other question.

Way to read, Disch.

nevermind.
Last edited on
Topic archived. No new replies allowed.