Hello, I have written this program, forgive me , this is my first program after " hello world".
Code:
# include <stdio.h> /* */
#include <stdlib.h> /* */
int main(void)/* */
{
int sum, char1, char2, char3, char4;/* */
printf( "Please enter four characters:\n"); /**/
char1 = getchar();/**/
char2 = getchar();/**/
char3 = getchar();/**/
char4 = getchar();/**/
printf("The first character you entered is: %c,", char1 );/**/
printf(" the ASCII value is %d.\n", char1 );
printf("The second character you entered is: %c,", char2 );
printf(" the ASCII value is %d.\n", char2 );
printf("The third character you entered is: %c,", char3 );
printf(" the ASCII value is %d.\n", char3 );
printf("The fourth character you entered is: %c,", char4 );
printf(" the ASCIIV value is %d.\n", char4 );
sum = char1 + char2 + char3 +char4;
printf("The sum of the ASCII values = %d\n",sum);
system("pause");/**/
}
How can i make the program display an error message if the user enters more than four characters?
Also any feedback on how I can improve the program?