If/Else Homework
A “magic” number is an integer in which the number is equal to the sum of the cubes of its digits. Write a program to determine whether a three digit number entered by the user is a magic number.
I have started on this but I do not know how to continue! Please give me hints or tips!
1 2 3 4 5 6 7 8 9 10
#include <iostream>
#include <cmath>
usingnamespace std;
int main () {
int x,y,z;
cout<<"Input the first digit of the 3 digit number: " ;
cin>>x;
cout<<"Input the second digit of the 3 digit number: ";
cin>>y;
cout<<"Input the third digit of the 3 digit number: ";
#include <iostream>
#include <cstdio>
#include <cstdlib>
usingnamespace std;
int manual()
{
int set[256];
int size = 0;
int relay = 0;
int total = 0;
int number = 0;
cout << "Enter how many digits are in number: ";
cin >> size;
cout << "Enter number: ";
cin >> number;
for(int relay2 = 0;relay2 < size;relay2++)
{
cout << "Next digit: ";
cin >> relay;
set[relay2] = relay;
}
for(int relay3 = 0;relay3 < size;relay3++)
{
relay = set[relay3];
relay = relay * relay * relay;
total += relay;
}
if(total == number)
{
cout << number << " is a magic number!" << endl;
}
else
{
cout << number << " is not a magic number." << endl;
}
system("PAUSE");
return 0;
}
int main(int nNumberofArgs, char* pszArgs[])
{
char input;
cout << "Welcome to magic number finder! Enter 'M' to find out if your number is magic. Enter 'A' to abort: ";
cin >> input;
switch(input)
{
case'm':
case'M':
manual();
break;
case'a':
case'A':
return 0;
break;
default:
cout << "M or A. How hard is it?" << endl;
return 0;
}
}