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
#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;
}
Comments
Leave a comment