170k views
0 votes
Write a C++ program to accept a bunch of numbers from the user. Accept the numbers in a loop and stop when the user enters 0. Print the cube of the numbers as they come in. You can use the math library. You don’t have to account for floating point precision. Sample Run: Enter the numbers(0 to stop):12 The cube is 1728 -8 The cube is -512 3.93 The cube is 60.70 -22.5 The cube is -11390.63 0

User Kajol
by
6.4k points

1 Answer

3 votes

Answer:

#include <iostream>

using namespace std;

int main() {

float n;//declaring a float variable.

cout<<"Enter 0 to stop"<<endl;//printing the message.

cin>>n;//prompting n.

while(n!=0)//taking input until n is not 0.

{

cout<<"The cube is "<<n*n*n<<endl;//printing the cube.

cin>>n;

}

return 0;

}

Input:-

12

-8

3.93

-22.5

0

Output:-

Enter 0 to stop

The cube is 1728

The cube is -512

The cube is 60.6985

The cube is -11390.6

Step-by-step explanation:

I have declared a float variable n.I am prompting n from the user and letting the user know that he has to enter 0 to stop until the user shall type inputs.In the loop I am simultaneously printing the cubes of the numbers entered.

User Darwyn
by
6.3k points