Answer to Question #320795 in C++ for John

Question #320795

Vowels Survival



by CodeChum Admin



Make me a program that accepts two random strings. Then, count the number of vowels that are in each of the strings and put it on separate variables.




Finally, for the survival of the vowels, subtract the total count of vowels of the first string to the vowels of the second string then print out its difference.




Easy, right? Then go and code as if your life depends on it!




Input



Two lines containing a string on each.



C++·is·fuN CodeChum·is·AWEsome



Output



A line containing an integer.



6




1
Expert's answer
2022-03-30T14:10:16-0400
#include<iostream>
#include<string>
#include<cmath>

using namespace std;

int main()
{
	string firstWord, secondWord;
	cout << "Please, enter the first string: ";
	getline(cin, firstWord, '\n');
	cout << "Please, enter the second string: ";
	getline(cin, secondWord, '\n');
	int count1=0, count2=0;
	for (int i = 0; i < firstWord.size(); i++)
	{
		firstWord[i]=tolower(firstWord[i]);
		if (firstWord[i] == 'a' || firstWord[i] == 'e' || firstWord[i] == 'i' ||
			firstWord[i] == 'o' || firstWord[i] == 'u' || firstWord[i] == 'y' )
		{
			count1++;
		}
	}
	for (int i = 0; i < secondWord.size(); i++)
	{
		secondWord[i]=tolower(secondWord[i]);
		if (secondWord[i] == 'a' || secondWord[i] == 'e' || secondWord[i] == 'i' ||
			secondWord[i] == 'o' || secondWord[i] == 'u' || secondWord[i] == 'y')
		{
			count2++;
		}
	}
	cout << "The difference of counts of vowels is " << abs(count1 - count2);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog