Hi all,
I am a new member here, I have some problem with my C++ code. I was trying to understand string programming. I was wondering if there anyone would be able to see through my codes and fix it up and explain to me as well.
#include <iostream>
#include <string>
using namespace std;
bool isVowel(char x);
void Vowel(string x);
void nonVowel(char begin, string end);
int main()
{
string line;
char ch;
cout <<"Masukkan Nama anda : ";
getline (cin,line);
string word,notFirst,first;
while (line.length()!=0)
{
int wordlen = line.find(" ");
if (wordlen >0)
{
word = line.substr(0,wordlen);
first=word.substr(0,1);
ch = first[0];
string notFirst(word,1);
}
if(isVowel(ch))
{
Vowel(word);
}
else
{
nonVowel(ch,notFirst);
}
}
return 0;
}
bool isVowel(char x)
{
char low_case=tolower(x);
if(low_case =='a')
return true;
else if (low_case =='e')
return true;
else if (low_case =='i')
return true;
else if (low_case =='o')
return true;
else if (low_case =='u')
return true;
else if (low_case =='y')
return true;
else
return false;
}
void vowel (string x)
{
string newWord;
newWord = x + "way";
cout <<newWord<<endl;
}
void nonVowel(char begin, string end)
{
string newWord;
newWord = end + begin +"ay";
cout <<newWord<<endl;
}