C++ Program that continually calculates the cube of a number until the user enters a number that is divisible 2
Object:
Write a program that continually calculates the cube of a number until the user enters a number that is divisible by both 2 and 3. Expected Output:
Enter a number: 3
Cube of 3 is: 27
Enter a number: 2
Cube of 2 is: 8
Enter a number: 12. C++ projects.
Code:
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int sq,num;
while(1)
{
cout<<“Enter Any Number: “;
cin>>num;
if(num%2==0 && num%3==0)
{
break;
}
else if(num!=0)
{
sq=pow(num,3);
cout<<“Cube of “<<num<<” is:”<<sq<<endl;
}
}
getch();
}
#include<iostream> #include<conio.h> using namespace std; void main() { int sq,num; while(1) { cout<<"Enter Any Number: "; cin>>num; if(num%2==0 && num%3==0) { break; } else if(num!=0) { sq=pow(num,3); cout<<"Cube of "<<num<<" is:"<<sq<<endl; } } getch(); }
Output:
Pingback: Write a program that will calculate the selling price of a circuit board that costs $12.67