Friday, July 31, 2009

Please recode my program I think I have error with this..?

Write a program that will ask the user to input 10 characters. Thereafter your program should output how many of the input data are LETTERS, NUMBERS and SPECIAL CHARACTERS.





#include %26lt;stdio.h%26gt;


#include %26lt;conio.h%26gt;


main()


{


char str[10];


int c,n,s,i,x;


int ch;


clrscr();





for (i=0; i%26lt;10; i++)


{


printf("Please Enter 10 numbers or characters");


scanf("%s", str[x]);


if((ch[i]%26gt;='A' %26amp;%26amp; ch[i]%26lt;='Z') :: (ch[i]%26gt;='a' %26amp;%26amp; ch[i]%26lt;='z'))





n++;





else if (ch[i]%26lt;='0' %26amp;%26amp; ch[i]%26gt;='9')





c++;





else


}


}


printf ("letters%c\n",c);


printf("numbers%d\n",n);


printf("special character\n",s);


getch();


}





I dont know how to fix this... please someone fix this, that the user can input 10 numbers, letters, and special characters. and tell how many numbers, letters, and special characters...


thank you for the help..

Please recode my program I think I have error with this..?
1. printf("Please enter...."


scanf("%s"..)


should be before the for loop.


2. scanf("%s", str); should be used in place of


scanf("%s",str[x]);


3. in the condition statements you need to use str[i] instead of ch[i].


4. the OR operator should be || . In the question it looks like ::.





**** Added later ****


The list of corrections need to include what Chris has observed. I missed them out..


***********************
Reply:No error





رشا السقا


رشا السقا
Reply:I dunno if its just Yahoo Answers formatting but the braces { } dont seem to match





should not your else have an opening brace {





also the ascii value of 0 is less then that of 9 so your greater then and less then symbols appear to be inverted.





Aside that I see no particular problem with your logic.





Hope this identifies the problem for you


No comments:

Post a Comment