Carry numbers to the left

Hi. I was trying to do this exercise:
When we learn to add numbers, they soon tell us that of "taking one": when the two digits we add reach the ten we have "carry" that we must add to the following digits (on the left).

When our teachers gave us exercises, before they had to count how many times we would have to "take one" and based on that they measured the difficulty of the exercise.

Can you make a program that automates that task?

My program:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
using namespace std;

int main() {
    int num1;
    int num2;
    int acarreo=0;
    while(1){
        cin>>num1>>num2;
        if(num1==0 && num2==0){
            break;
        }
        else{
            for(int n=0;n<num1;n++){
                if(num1%10+num2%10 >=10){
                    acarreo++;
                }
                num1=num1/10;
                num2=num2/10;
            }
        }
        cout<<acarreo<<endl;
        acarreo=0;
    }
	return 0;
}

Maybe someone finds the mistake?
I want to output the num of carry's
Last edited on
How does the mistake show?

Does the compilation fail?
Does the program crash?
Does the program produce unexpected results?


How many digits are there to add? Does 9000+1 really have 9000 chances to add one?

Q: How many times you must add one with these:
 46
+57
---

A:
6+7 = 3 and carry one
4+5+1 = 0 and carry one
0+0+1 = 1
Topic archived. No new replies allowed.