Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard
#include<iostream.h>
#include<string.h>
int word(char);
void main()
{
char w[30];
cout << "Please enter a word: ";
cin >> w;
cout << word(w);
}
int word(char x)
{
if( x[0] != 'a')
{
return ?;
}
else
{
return ?;
}
}int number_of_a_s(char value[20]);
int main() {
char input[20];
cout<<"Please enter a word\n";
cin>>input;
cout<<"\n\nNumber of a's in word: "<<number_of_a_s(input)<<"\n";
system("Pause");
}
int number_of_a_s(char value[20]) {
int counter=0;
for(int i=0;i<20;i++) {
if (value[i]== 'a')
counter++;
}
return counter;
}jinx wrote:what i need to do is to check the letters of the array. To see if its a "a" or not.
1.i need to check the first letter of the array if its "a" if not move on to the second letter and so on.
2.my output should say how many "a" i have on the word.
#include<iostream.h>
#include<string.h>
int word(char*);
void main()
{
char w[30];
cout << "Please enter a word: ";
cin >> w;
cout << word(w);
}
int word(char *x)
{
int ctr = 0;
if( *x != 'a')
{
return word(x+1);
}
else
{
return word(x+1);
}
}Users browsing this forum: Google [Bot] and 1 guest