Sorry, I'm not quite sure what you're after when you say
I'm supposed to replace the vowels that have an uneven number with "BAC".
Vowels are (as you correctly used in your code) a, e, i, o, u. But what is this even/uneven number you mean that is associated with a vowel? Is it their index in the alphabet (0- or 1-based)? Is it their (ASCII) character code?
Or maybe you're supposed to replace words that have an uneven number of vowels in them with "BAC", not the vowels themselves? (E.g.: "cow" --> "BAC", because single vowel, or "vitamin" --> "BAC", because 3 vowels, but "learn" --> "learn", as 2, i.e., an even number of vowels.
Your code is checking for vowels at even positions. Is this what you need?
Could you please specify what you're after? Maybe use a few examples as an illustration?
f you're looking for the example as I described in bold, then you are supposed to count the vowels and decide after every word, if you're supposed to print it as it was (p), or print "BAC" instead.
I've added some comments in your code so you'd know where to add the new logic:
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char s[101], *p;
int ok, i = 0;
cin.get(s, 101);
p = strtok(s, " ");
while (p)
{
int vowelCount = 0;
for (i = 0; i < strlen(p); i++)
{
// Iterate through all th characters of `p`
{
// If any character of p is a vowel, increment `vowelCount`.
}
}
// If vowelCount is even, print p, else print "BAC".
p = strtok(NULL, " ");
}
return 0;
}Good luck!