My assignment is to use C programming to write a program that gets a list of words from the user as input and outputs the largest and the smallest word provided. Your solution also must output the number of vowels in both words. You must use functions in your code
· TEST YOUR CODE WITH THIS, type 10 countries from the list below as input:[Argentina, Australia, Brazil, Canada, China, France, Germany, India, Indonesia, Italy, Japan, Republic of Korea, Mexico, Russia, Saudi Arabia, South Africa, Turkey, UK, USA, UK]
The program is printing the largest word and the smallest word properly and i've used functions as well
But there's a problem with the number of vowels between the largest word and the smallest word.
There's no errors but the problem is when the program is executed it prints the largest word and then the number of vowels of the largest word. But when it comes to the smallest word it basically prints the same number of vowels as the largest word.
For example: If I enter 10 countries like Argentina, Australia, Brazil, Canada, China, France, Germany, India, Indonesia, Italy
The complier says:
The largest word is Argentina
The number of vowels in the string Argentina is 4
The smallest word is China
The number of vowels in the string China is 4
But the number of vowels of China is 2 not 4
So, I don't know where i've gone wrong.
Here's my code:
#include
#include
/*GLOBAL METHOD DECLARATION*/
int isVowel(char c);
int main()
{
/*LINE 11 TO LINE 20 ARE USED TO DELCARE MY VARIABLES*/
int i=0;
int j=0;
int k=0;
int a;
int minIndex=0;
int maxIndex=0;
int max=0;
int min=0;
char countries[100],lswords[100][100];
printf("**********WORD LENGTH AND VOWELS COUNTER**********\n");
printf("\n***THIS PROGRAM GETS A LIST OF WORDS FROM THE USER AS INPUT AND,\n");
printf("OUTPUTS THE LARGEST AND THE SMALLEST WORD PROVIDED");
printf("\nYOUR PROGRAM ALSO MUST OUTPUT THE NUMBER OF VOWELS IN BOTH WORDS\n");
printf("\n\tHERE'S A LIST OF 10 COUNTRIES:\n\t");
printf("\n\tARGENTINA,AUSTRALIA, BRAZIL, CANADA, CHINA, FRANCE, GERMANY, INDIA, INDONESIA, ITALY,\n\t");
printf("\n\tJAPAN, REPUBLIC OF KOREA, MEXICO, RUSSIA, SAUDI ARABIA, SOUTH AFRICA, TURKEY, UK, USA\n\t");
printf("\nENTER 10 COUNTRIES FROM THE LIST ABOVE AS AN EXAMPLE OF AN INPUT:\n");
printf("\n");
gets(countries); /*THIS ALLOWS THE USER TO INPUT A STRING AND STORES THE DATA IN COUNTRIES*/
while(countries[k]!='\0') /*THIS IS USED TO SPLIT THE SENTENCES*/
{
j=0;
while(countries[k]!=' '&&countries[k]!='\0')
{
lswords[i][j]=countries[k];
k++;
j++;
}
lswords[i][j]='\0';
i++;
if(countries[k]!='\0')
{
k++;
}
}
int len=i;
max=strlen(lswords[0]);
min=strlen(lswords[0]);
/*LINE 60 TO 72 IS USED AFTER SPLITTING THE LENGTH OF STRING*/
/*AND FINDING ITS INDEX USING MAX LENGTH AND MIN LENGTH*/
for(i=0;i max)
{
max=a;
maxIndex=i;
}
if(a
{
min=a;
minIndex=i;
}
}
int counter =0;
int v=0;
while(lswords[maxIndex&&minIndex][v]!='\0')
{
if(isVowel(lswords[maxIndex&&minIndex][v]))
counter++;
v++;
}
printf("\nTHE LARGEST WORD IS: %s\n", lswords[maxIndex]);
printf("\nTHE NUMBER OF VOWELS IN THE STRING '%s' is: %d\n", lswords[maxIndex],counter);
printf("\nTHE SMALLEST WORD IS: %s\n",lswords[minIndex]);
printf("\nTHE NUMBER OF VOWELS IN THE STRING '%s' is: %d\n", lswords[minIndex],counter);
return 0;
}
int isVowel(char c)
{
char vowels[]= {'a', 'e','i','o','u','A','E','I','O','U'};
int v;
for(v=0;v<=9;v++)
{
if(c==vowels[v])
return 1;
}
return 0;
}
Answers
Answered by
5
Explanation:
LINE 11 TO LINE 20 ARE USED TO DELCARE MY VARIABLES*/
int i=0;
int j=0;
int k=0;
int a;
int minIndex=0;
int maxIndex=0;
int max=0;
int min=0;
char countries[100],lswords[100][100];
printf("**********WORD LENGTH AND VOWELS COUNTER**********\n");
printf("\n***THIS PROGRAM GETS A LIST OF WORDS FROM THE USER AS INPUT AND,\n");
printf("OUTPUTS THE LARGEST AND THE SMALLEST WORD PROVIDED");
printf("\nYOUR PROGRAM
Answered by
0
Answer:
PLZ SUBSCRIBE MY YOUTUBE CHANNEL DARJEX GAMING
PLZ MARK ME AS BRAINLIEST
Similar questions
Social Sciences,
2 months ago
Biology,
4 months ago
English,
10 months ago
Science,
10 months ago
Physics,
10 months ago