English

Suppose x and y are two double-type variables that you want to add as integer and assign to an integer variable. Construct a C++ statement to do the above.

Advertisements

Question

Suppose x and y are two double-type variables that you want to add as integer and assign to an integer variable. Construct a C++ statement to do the above.

Code Writing
Advertisements

Solution

double x, y;
int sum;
x = 12.64;
y = 13.56;
sum = (int) x + (int) y;
The variable sum will have a value of 25 due to explicit casting.

shaalaa.com
Variables of Built-in-data Types
  Is there an error in this question or solution?
Chapter 9: Introduction to C++ - Data Types, Variables and Expressions - Evaluation - Section - B [Page 151]
Advertisements
Share
Notifications



      Forgot password?
Use app×