C++ program have the user enter a two digit integer. calculate and display the square, raised to the power of 3, square root, and the sum of the digits of the user input.
Output should look as follows
Enter an integer 56
The square of 56 is 3136
56 raised to the 3rd power is 175616
the square root of 56 is 7.48
the sum of the digits in 56 is 11
(im stuck on how to write the sum of the digits part)
(THIS IS WHAT I HAVE SO FAR)
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
float num1,sum, num2;
cout << "Enter a two digit integer: ";
cin >> num1, num2;
cout << "The square is: ";
cout << num1 * num1<<endl;
cout << "The 3rd power is: ";
cout << pow(num1, 3)<< endl;
cout << setprecision(3);
cout << "The square root is: ";
cout << sqrt(num1)<< endl;
This does not do what you think. Don't try to use the comma operator this way. Pretty much the only thing it's good for is for function parameter lists, and array initialization lists. If you try to use it anywhere else you're probably using it incorrectly.
Furthermore, if the user is supposed to entering an integer, you should receive it as an integer (int), not as two floats.
Lastly, you can extract "digits" of an integet by dividing (/) and modding (%) by 10. Note that this won't work with floats -- the variable has to be an integer.