#include "stdafx.h"
#include <iostream>
#include <string>
int main(){
std::string vowelor[] {"My name is Matilda"}{
for (int i = 0; i < vowelor[3].length; i++){
if (i == "a" || i == "e" || i == "o" || i == "u"){
int a = 0;
a = a + 1;
}
}
}
I don't know what to do with the underlined bracket( after {"My name is Matilda"} at the end of line 7) , I tried semicolons and both but there's still an error.Also I think I'm sure there's another logical error with the program, but I don't know..help please.
#include "stdafx.h"
#include <iostream>
#include <string>
int main(){
std::string vowelor[] {"My", "name", "is", "Matilda"}{
for (int i = 0; i < vowelor[3].length; i++){
if (i == "a" || i == "e" || i == "o" || i == "u"){
int a = 0;
a = a + 1;
}
}
}
}
I'm still having a problem, and I don't know what it is, should I re-read the arrays and loops tutorials?
#include <iostream>
#include <cstring>
#include <string>
usingnamespace std;
int main()
{
//initialise array of words
string words[] = { "My", "name", "is", "Matilda" };
//N number of words, M number of letters of a word
int N = 4, M;
int nr;
for (int i = 0; i < N; i++)
{
nr = 0;
M = strlen(&words[i][0]); //get length of current word
//strlen takes as argument the adress of the first position of a array(strings are like arrays)
//so you pass the first position of the current word with & in front
for (int j = 0; j < M; j++)
{
//if the current character of the current word is a vowel increment nr
if (strchr("aeiouAEIOU", words[i][j]) != NULL)
nr++;
}
cout << words[i] << " has " << nr << " vowels" << endl;
}
}