First off, indent your code! If you don't - and you haven't - then it gets harder to work out what is going on. It's not too bad with small code like this, but when it gets bigger it can get extremely difficult if you don't indent correctly.
Indentation style - Wikipedia[
^]
I don't care if you use Whitesmiths:
#include <stdio.h>
int main()
{
int choice = 1;
while (choice == 1)
{
int n, count =0;
printf("enter an integer = ");
scanf("%d", &n);
int buffer = n;
while (buffer!=0)
{
buffer/=10;
count++;
}
printf("your number %d has %d digits", n, count);
printf("\n Do you want to use another number? (1 or A if Yes 2 Or B if NO)\n");
scanf("%d", &choice);
}
return 0;
}
Or even the execrable 1TB:
#include <stdio.h>
int main(){
int choice = 1;
while (choice == 1){
int n, count =0;
printf("enter an integer = ");
scanf("%d", &n);
int buffer = n;
while (buffer!=0){
buffer/=10;
count++;
}
printf("your number %d has %d digits", n, count);
printf("\n Do you want to use another number? (1 or A if Yes 2 Or B if NO)\n");
scanf("%d", &choice);
}
return 0;
}
Just pick a style and stick to it!
When you use scanf to read from the console, the type of value it returns depends on exactly what you specify in the format string: in your case "%d" fetches an integer value, so if your user types "1" and presses ENTER it will work ... but if he presses "A" it will lock up, crash, or otherwise fail because "A" is not an integer number!
What I would suggest is that you use scanf to return a string, and parse that to find out what the user entered:
char inp[100];
scanf("%s", inp);
choice = atoi(inp);
And get rid of the "A" / "B" option.