Hello!
I'm currently learning C++ and I have kind of gone stuck on this task:
"Write a program that, with help of type conversion, converts a entered decimal number to the closest integer. For example, the number 35.8 would be rounded off to 36."
This is what I have written:
The problem is, that if I enter for example 35.8, it prints out 35. How do I make it round off to the closest number? I'm using Xcode 6.1, if that's to any help.
Thanks in advance!
I'm currently learning C++ and I have kind of gone stuck on this task:
"Write a program that, with help of type conversion, converts a entered decimal number to the closest integer. For example, the number 35.8 would be rounded off to 36."
This is what I have written:
Code:
int main(int argc, const char * argv[]) {
float number;
cout << "enter a number: ";
cin >> number;
cout << "The number is: " << (int)number << endl;
return 0;
The problem is, that if I enter for example 35.8, it prints out 35. How do I make it round off to the closest number? I'm using Xcode 6.1, if that's to any help.
Thanks in advance!