Can someone provide code and explain to me logic behind this? Struggling with AS
ID: 3589404 • Letter: C
Question
Can someone provide code and explain to me logic behind this? Struggling with ASCII concept.
Write a program that has user enter a number between 33 and 126 (if it is outside that range, display error message & end program); Display its corresponding characters with one of the following messages:
The character _ is a vowel
The character _ is a consonant
The character _ is a digit
The character _ is not a digit or a letter
If the character is a letter also display the message 'This is the first character in my name" ONLY if it is actually the first letter of your name (name used in example is Lisa). Use ASCII character set.
Explanation / Answer
#include <stdio.h>
#include <string.h>
int main()
{
int num,chkName;
char yourName[30];
printf("Enter a number betweeen 33 to 126 to get its ASCII character ");
scanf("%d",&num);
printf("Enter your name ");
scanf("%s",yourName);
chkName=(int)yourName[0];
if((num<33) || (num > 126))
{
printf("ERROR: Entered number is outside of range 33 to 126..Exiting.. ");
return 0;
}
else if((num>=65 && num<=90)||(num>=97 && num<=122))
{
if((num==65)||(num==69)||(num==73)||(num==79)||(num==85)||(num==97)||(num==101)||(num==105)||(num==111)||(num==117))
{
printf("ASCII equivalent of Entered value is %c and it is a vowel ",num);
}
else
{
printf("ASCII equivalent of Entered value is %c and it is a Consonant ",num);
}
}
else if((num>=48)&&(num<=57))
{
printf("ASCII equivalent of Entered value is %c and its a digit ",num);
}
else{
printf("ASCII equivalent of Entered value is %c and its neither digit nor a number ",num);
}
if(chkName==num)
{
printf("Congratulations!! The entered value is the ASCII equivalent of first letter of your name ");
}
return 0;
}