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

Conversation

tanishq-singh-2407
Copy link
Contributor

@tanishq-singh-2407 tanishq-singh-2407 commented Oct 5, 2022

Description

Closes #986

Type of Change

  • Adding a new entry

Checklist

  • All writings are my own.
  • My entry follows the Codecademy Docs style guide.
  • My changes generate no new warnings.
  • I have performed a self-review of my own writing and code.
  • I have checked my entry and corrected any misspellings.
  • I have made corresponding changes to the documentation if needed.
  • I have confirmed my changes are not being pushed from my forked main branch.
  • I have confirmed that I'm pushing from a new branch named after the changes I'm making.
  • Under "Development" on the right, I have linked any issues that are relevant to this PR (write "Closes # in the "Description" above).

@Dusch4593
Copy link
Contributor

@tanishq-singh-2301 Thanks for doing that, much appreciated! 😄 After I'm finished with review I'll tag you again so you can implement the feedback.

@tanishq-singh-2407
Copy link
Contributor Author

Sure,
Thanks.

@Dusch4593 Dusch4593 added c++ C++ entries new entry New entry or entries hacktoberfest labels Oct 5, 2022
Copy link
Contributor

@Dusch4593 Dusch4593 left a comment

Choose a reason for hiding this comment

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

@tanishq-singh-2301 Left you some comments/suggestions to look at. Tag when when you're finished with implementing the feedback and I'll take another look. 😄

result = std::round(num);
```

## Codecademy Example
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
## Codecademy Example
## Codebyte Example

- 'paths/computer-science'
---

The `round()` function returns the integral value 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
The `round()` function returns the integral value that is nearest to the argument, with halfway cases rounded away from zero.
The `round()` function returns the integer that is nearest to the argument, with halfway cases rounded away from zero.

@@ -0,0 +1,52 @@
---
Title: 'round()'
Description: 'Returns the integral value 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 integral value 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 zero.'

Comment on lines 18 to 20

The `cmath` library must be added at the top of the file.

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 `cmath` library must be added at the top of the file.

I would omit this line since this point is covered in the parent math functions entry.

The `cmath` library must be added at the top of the file.

```cpp
std::round(double num);
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::round(double num);
round(num);

std::round(double num);
```

Argument must be a `double`/`float`/`long double`, and the return value will be the type of `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
Argument must be a `double`/`float`/`long double`, and the return value will be the type of `integer`.
The `num` parameter must be a `double`,`float`, or `long double`. The return value will be an integer.

@tanishq-singh-2407
Copy link
Contributor Author

Done.
Please review updated code @Dusch4593

Thanks

Copy link
Contributor

@Dusch4593 Dusch4593 left a comment

Choose a reason for hiding this comment

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

@tanishq-singh-2301 Just a few more comments from me 😄

- 'paths/computer-science'
---

The `round()` function 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
The `round()` function returns the integer that is nearest to the argument, with halfway cases rounded away from zero.
The **`round()`** function returns the integer that closest to the argument, with halfway cases rounded away from zero.

content/cpp/concepts/math-functions/terms/round/round.md Outdated Show resolved Hide resolved

## Codebyte Example

Use `round()` to round-off `10.89`:
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
Use `round()` to round-off `10.89`:
The following example is runnable and rounds the halfway case away from zero:

@tanishq-singh-2407
Copy link
Contributor Author

Done.
Please review updated code @Dusch4593

Thanks

Copy link
Contributor

@Dusch4593 Dusch4593 left a comment

Choose a reason for hiding this comment

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

@tanishq-singh-2301 Just looked over your latest batch of changes. I left some final comments/suggestions for my review. After you implement this feedback, we will proceed to one more review of this entry. 😄

Comment on lines 23 to 24
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.
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.

Comment on lines 43 to 49
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. 😄

Comment on lines 26 to 39
## 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

Comment on lines 66 to 67
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.

@@ -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.'

- '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.

@tanishq-singh-2407
Copy link
Contributor Author

working on it!

@tanishq-singh-2407
Copy link
Contributor Author

Done, please review and tell me if any more changes is required?
@Dusch4593

Thanks

@tanishq-singh-2407 tanishq-singh-2407 requested review from HishamT and Dusch4593 and removed request for HishamT and Dusch4593 October 13, 2022 04:47
Copy link
Collaborator

@HishamT HishamT left a comment

Choose a reason for hiding this comment

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

LGTM!

@tanishq-singh-2407
Copy link
Contributor Author

Okay

@tanishq-singh-2407
Copy link
Contributor Author

any update? @HishamT

Copy link
Collaborator

@HishamT HishamT left a comment

Choose a reason for hiding this comment

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

LGTM!

@tanishq-singh-2407 tanishq-singh-2407 requested review from HishamT and Dusch4593 and removed request for HishamT and Dusch4593 October 17, 2022 20:24
Copy link
Contributor

@yangc95 yangc95 left a comment

Choose a reason for hiding this comment

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

I had one additional comment before merge. @tanishq-singh-2301

round(num);
```

The `num` parameter must be a `double`,`float`, or `long double`. The return value will be an integer. If the decimal in num is `0.5` or higher, the closest integer greater than `num` is returned.
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. If the decimal in num is `0.5` or higher, the closest integer greater than `num` is returned.
- The `num` parameter must be a `double`,`float`, or `long double`.
- The return value will be an integer.
- If the decimal in num is `0.5` or higher, the closest integer greater than `num` is returned.

Copy link
Contributor

@yangc95 yangc95 left a comment

Choose a reason for hiding this comment

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

LGTM

@Dusch4593 Dusch4593 merged commit cc27e6e into Codecademy:main Oct 24, 2022
@github-actions
Copy link

👋 @tanishq-singh-2301
You have contributed to Codecademy Docs, and we would like to know more about you and your experience.
Please take a minute to fill out this four question survey to help us better understand Docs contributions and how we can improve the experience for you and our learners.
Thank you for your help!

@tanishq-singh-2407 tanishq-singh-2407 deleted the tanishq-singh-round branch October 24, 2022 19:20
@Dusch4593 Dusch4593 added the hacktoberfest-accepted Indicates the PR was approved, merged, and pertains to Hacktoberfest label Oct 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Term Entry] C++ Math Functions: round()
4 participants