Question

using C++ for beginners Create a function named Bear that takes in a double and returns...

using C++ for beginners

Create a function named Bear that takes in a double and returns the integer part (e.g. if it takes in 2.15 it returns 2)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the code


#include <stdio.h>
#include<iostream>

using namespace std;

//function bear which converts double to integer

int bear(double x) // double variable is passed to function bear
{
int y;
y=x; // when we assign double value to integer variable then fraction part is removed
return y; // returns integer
}
// Main code starts here
int main()
{
double variable;
int a;
cin>>variable;
a=bear(variable);

cout<<a;
return 0;
}

output

2.15

2

output snippet

Add a comment
Know the answer?
Add Answer to:
using C++ for beginners Create a function named Bear that takes in a double and returns...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT