Answer to Question #285187 in C++ for Francis

Question #285187

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-01-06T02:00:51-0500
#include <iostream>
#include <string>
#include <math.h>


using namespace std;




int getNumberVowels(string name) { 
	int numberVowels=0;
	string vowels = "AEIOUYaeiouy";
	for (int i = 0; i < name.size(); i++){
		for (int j = 0; j < vowels.size(); j++)
		{
			if (toupper(name[i]) == vowels[j])
			{
				numberVowels++;
			}
		}
	}
	return numberVowels;
}


int main()
{
	string string1;
	string string2;
	cout<<"Enter string 1: ";
	getline(cin,string1);
	cout<<"Enter string 2: ";
	getline(cin,string2);
	int numberVowelsString1=getNumberVowels(string1);
	int numberVowelsString2=getNumberVowels(string2);
	
	cout<<abs(numberVowelsString2-numberVowelsString1)<<"\n\n";




	system("pause");
	return 0;
}

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