I'm trying to make a program that can read and count how many digits a number has, this is my code so far
#include <stdio.h>
#include <stdlib.h>
int main(){
int a, b=0;
printf("Hey welcome to how many digits your number has!\n");
xyz:
printf("To begin enter a Number = ");
scanf("%d",&a);
while (a!=0) {
a/=10;
++b;
}
printf("your number has %d digits\n",b);
int choice;
printf("do you want to use another number?\nIf yes enter \"1\"\nif no enter \"2\"\n");
scanf("%d",&choice);
if (choice==1){
goto xyz;
}
else if (choice==2){
return 0;
}
return 0;
}
This works great for the first time around but when I go back up and repeat it seems that value of 'b' from previous attempt has been stored.. how can I start again without it storing the value of the variable 'b' and keep the value of b = 0?