Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New Term] C++ Math Functions: round() #1043

Merged
merged 21 commits into from
Oct 24, 2022
Merged
Changes from 7 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
28b78e6
New Entry: C++ Math Functions: `round()` (#986)
tanishq-singh-2407 Oct 4, 2022
6895c90
fix: removed unwanted fun `round()` from `main` (#986)
tanishq-singh-2407 Oct 5, 2022
bca068e
New Entry: C++ Math Functions: `round()` (#986)
tanishq-singh-2407 Oct 5, 2022
284e872
fix: sentences rephrased (#986)
tanishq-singh-2407 Oct 5, 2022
63c6fbf
Merge branch 'main' into tanishq-singh-round
tanishq-singh-2407 Oct 5, 2022
55828c9
:zap: fix: update example and sentences rephrased (#986)
tanishq-singh-2407 Oct 6, 2022
91469eb
Merge branch 'main' into tanishq-singh-round
tanishq-singh-2407 Oct 6, 2022
5f5a502
:zap: refactor: cpp math-function `round()` (#986)
tanishq-singh-2407 Oct 7, 2022
fbf7010
:zap: refactor: cpp math-function `round()` (#986)
tanishq-singh-2407 Oct 7, 2022
771c271
Merge remote-tracking branch 'refs/remotes/origin/tanishq-singh-round…
tanishq-singh-2407 Oct 7, 2022
b64ce3b
:zap: refactor: cpp math-function `round()` (#986)
tanishq-singh-2407 Oct 7, 2022
238ec91
Merge branch 'main' into tanishq-singh-round
tanishq-singh-2407 Oct 7, 2022
d4980c3
Merge branch 'main' into tanishq-singh-round
tanishq-singh-2407 Oct 7, 2022
36eddff
Merge branch 'main' into tanishq-singh-round
tanishq-singh-2407 Oct 7, 2022
244a7b9
Merge branch 'main' into tanishq-singh-round
tanishq-singh-2407 Oct 8, 2022
18612ae
Merge branch 'Codecademy:main' into tanishq-singh-round
tanishq-singh-2407 Oct 13, 2022
f4e5351
fix: changes and reword sentences
tanishq-singh-2407 Oct 13, 2022
fb20ea2
:rocket: fix: compile time error
tanishq-singh-2407 Oct 17, 2022
757c3b5
:rocket: fix: single line to `list` comment
tanishq-singh-2407 Oct 21, 2022
392672e
Merge branch 'main' into tanishq-singh-round
yangc95 Oct 24, 2022
c5bf18e
Update round.md
Dusch4593 Oct 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions content/cpp/concepts/math-functions/terms/round/round.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
Title: 'round()'
Description: 'Returns the integer that is nearest to the argument, with halfway cases rounded away from zero.'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Description: 'Returns the integer that is nearest to the argument, with halfway cases rounded away from zero.'
Description: 'Returns the integer that is nearest to the argument, with halfway cases rounded away from the ending zero.'

Subjects:
- 'Computer Science'
Tags:
- 'Functions'
- 'Arithmetic'
- 'Methods'
CatalogContent:
- 'learn-c-plus-plus'
- 'paths/computer-science'
---

The **`round()`** function returns the integer that is closest to the argument, with halfway cases rounded away from zero.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The **`round()`** function returns the integer that is closest to the argument, with halfway cases rounded away from zero.
The **`round()`** function returns the integer that is closest to the argument, with halfway cases rounded away from the ending zero.


## Syntax

```pseudo
round(num);
```

The `num` parameter must be a `double`,`float`, or `long double`. The return value will be an integer.
Dusch4593 marked this conversation as resolved.
Show resolved Hide resolved
In `halfway case` the number get round-off to the next closest integer.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The `num` parameter must be a `double`,`float`, or `long double`. The return value will be an integer.
In `halfway case` the number get round-off to the next closest integer.
The `num` parameter must be a `double`,`float`, or `long double`. The return value will be an integer. If `num` is a halfway case where the decimal place is `.5` or higher, then the closest integer above `num` is returned.


## Example 1

```cpp
double num = 4.5;
double result;

result = std::round(num);

std::cout << "The result is " << result << "!\n";
// Output: The result is 5!

```


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep the entry to just one "Example" and one "Codebyte Example". My suggestion here would be to combine the code from both of these snippets.

Suggested change
## Example 1
```cpp
double num = 4.5;
double result;
result = std::round(num);
std::cout << "The result is " << result << "!\n";
// Output: The result is 5!
```

## Example 2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Example 2
## Example


Dusch4593 marked this conversation as resolved.
Show resolved Hide resolved
```cpp
double num = 9.23;
double result;

result = std::round(num);

std::cout << "The result is " << result << "!\n";
// Output: The result is 9!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
double num = 9.23;
double result;
result = std::round(num);
std::cout << "The result is " << result << "!\n";
// Output: The result is 9!
#include <iostream>
#include <cmath>
int main() {
double num1 = 9.23;
double result1;
result1 = std::round(num1);
std::cout << "The result of round(9.23) is " << result1 << "!\n";
double num2 = 4.5;
double result2;
result2 = std::round(num2);
std::cout << "The result of round(4.5) is " << result2 << "!\n";
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should include the #includes statements along with the code being nested in a main() method so that if a reader copy/pastes this example they can run it. 😄

```

Dusch4593 marked this conversation as resolved.
Show resolved Hide resolved
Dusch4593 marked this conversation as resolved.
Show resolved Hide resolved
## Codebyte Example

The following example is runnable and rounds the halfway case away from zero:

```codebyte/cpp
#include <iostream>
#include <cmath>

int main() {
double num = 10.89;
double result;

result = std::round(num);

std::cout << "The result is " << result << "!\n";
// Output: The result is 11!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::cout << "The result is " << result << "!\n";
// Output: The result is 11!
std::cout << "The result is " << result << "!\n";

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for output comments in Codebyte snippets.

}
```