#include <iostream>
usingnamespace std;
int main()
{
int num, num2, sum = 0;
int div, num3, count = 0;
cout << "Enter an integer: ";
cin >> num;
cout << endl; // This is the freezing point.
count = 0;
while (num != 0)
{
num2 = num / 10;
count++;
}
num == num2;
do
{
div = static_cast<int>(pow(10, --count));
num3 = num2 / div;
num2 = div % div;
cout << num3 << ' ';
sum = sum + num3;
}
while (count != 0);
cout << "The sum of the integers is: " << sum
<< endl;
return 0;
}
Line 22: What do you think this line does? == is the equality operator. Did you mean to do an assignment here (=)?
Line 34: The ; terminates the while statement.
Line 26: If you're taking 10 to a negative power, the result is going to be a fraction (<1). Assigning the result to an int is going to result in 0.
Line 27: Guaranteed you're going to attempt to divide by 0 here.
Line 28: Modulo of a number by itself will always be 0.
Line 26: You use the pow() function, but don;t include the <cmath> header.
PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
I honestly don't understand the concept of the equation, or really for that fact, the concept of how to implement the for loop to solve the equation. Furthermore, the LCV concept is eluding me also. What I do understand is that the LCV is the condition that keeps the loop from going on endlessly, but I'm just not catching on to how to actually write one out. For example, in the while loop
1 2 3
while (num != 0)
{ num2 - num / 10;
count++}
I just cant come up with the correct algorithm to eventually make it false.