Question
Hi there! I have the following task in C++ I need help with: Implement a program that calculates the cube of a non-negative integer (i.e.
Hi there! I have the following task in C++ I need help with:
Implement a program that calculates the cube of a non-negative integer (i.e. raises the number to the third power) and prints it, or an error message if the calculation overflows.
Use int as the type of input and all other variables, it is enough that the program works with non-negative numbers. The program must comply with the following examples:
As you can see from the third example run, with a sufficiently large input value, the result of the calculation will not be a negative but a positive number. So it is not enough to check whether the result is positive.
Thank you for your help!
Enter a number: 2 The cube of 2 is 8. Enter a number: 100000 Error! The cube of 100000 is not 1530494976. Enter a number: 200000000 Error! The cube of 200000000 is not 134217728Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started