PDA

View Full Version : Help wanted in C++ programming


chinthakapathir
05-29-2009, 08:31 PM
hey guys does anybody here know C++??

This is the question.

Write a program using arrays to input a sentence and calculate the vowels in the sentence. Can any genius here help me? Pls? Need the program code.

Sudantha_s
05-29-2009, 08:58 PM
hey guys does anybody here know C++??

This is the question.

Write a program using arrays to input a sentence and calculate the vowels in the sentence. Can any genius here help me? Pls? Need the program code.









#include<stdio.h>

main()
{

char str[25];
char search;
int count=0;

printf("Enter a String : ");
fflush(stdin);
gets(str);

printf("Enter a Word to Search : ");
scanf("%c",&search);

for(int i=0;i<25;i++)
{
if(str[i]==search)
{
count++;
}
}

printf("That Characther Found %d Time(s)",count);
}

Sudantha_s
05-29-2009, 08:59 PM
Thats for Find a Character in a sentence .. change the logic in to vowels like if variable == A E I Q u

chinthakapathir
05-29-2009, 09:04 PM
#include<stdio.h>

main()
{

char str[25];
char search;
int count=0;

printf("Enter a String : ");
fflush(stdin);
gets(str);

printf("Enter a Word to Search : ");
scanf("%c",&search);

for(int i=0;i<25;i++)
{
if(str[i]==search)
{
count++;
}
}

printf("That Characther Found %d Time(s)",count);
}

Thanks i got some kind of idea about it. can you kindly type this in c++ commands coz i dont know these commands fflush,gets. Only did the basic stuff in C. Need c++ coding. thanks .

Sudantha_s
05-29-2009, 09:05 PM
Thanks i got some kind of idea about it. can you kindly type this in c++ commands coz i dont know these commands fflush,gets. Only did the basic stuff in C. Need c++ coding. thanks .



sorry machan this is C ...i dnt knw abt C ++ :D

chinthakapathir
05-29-2009, 09:07 PM
ela thanks anyway machan

Sudantha_s
05-29-2009, 09:18 PM
ela thanks anyway machan


This is ur coding using C




#include<stdio.h>

main()

{

char word[10];
int val=0;
int i;

printf("Enter a String : ");
gets(word);

for(i=0;word[i]!='\0';i++)
{

if(word[i]=='a'||word[i]=='e'||word[i]=='i'||word[i]=='o'||word[i]=='u')
{
val++;

}

}

printf("Vowel Count is : %d",val);
printf("\nNumber of Constances : %d",i-val);




}

¤--bACarDi--¤
05-29-2009, 09:32 PM
Machan meken count wenne vowel sounds nemei vowel letters....k
Awlak thiyenawanam kiyapan....;)


#include <iostream>
using namespace std;
int main ()
{
char string[25];
int count=0;
cout<<"Enter String:";
cin>>string;

for (int j=0;j<26;j++)
{
switch (string[j])
{
case 'a': count++; break;
case 'e': count++; break;
case 'i': count++; break;
case 'o': count++; break;
case 'u': count++; break;
}
}
cout<<"There are "<<count<<" Vovels"<<endl;
}

shanaka perera
05-29-2009, 09:43 PM
g++ -oabc abc.cpp

chinthakapathir
05-30-2009, 09:38 AM
Machan meken count wenne vowel sounds nemei vowel letters....k
Awlak thiyenawanam kiyapan....;)


#include <iostream>
using namespace std;
int main ()
{
char string[25];
int count=0;
cout<<"Enter String:";
cin>>string;

for (int j=0;j<26;j++)
{
switch (string[j])
{
case 'a': count++; break;
case 'e': count++; break;
case 'i': count++; break;
case 'o': count++; break;
case 'u': count++; break;
}
}
cout<<"There are "<<count<<" Vovels"<<endl;
}


machan meken wenne enter karana sentence eke first word eke no. of vowels print wena eka witharai. always the vowels in the first word.

E.g: " Investigation is successful"
it prints "There are 6 vowels.

Only the first word. How to calculate the no.of vowels in the whole sentence?
I think we have to separate each word into one subscript in the array
array[1]=Investigation
array[2]=is
array[3]=successful

and then calculate the no.of vowels in each word and then output the total no. of vowels in the whole sentence, how to do this.

¤--bACarDi--¤
06-02-2009, 11:55 AM
machan meken wenne enter karana sentence eke first word eke no. of vowels print wena eka witharai. always the vowels in the first word.

E.g: " Investigation is successful"
it prints "There are 6 vowels.

Only the first word. How to calculate the no.of vowels in the whole sentence?
I think we have to separate each word into one subscript in the array
array[1]=Investigation
array[2]=is
array[3]=successful

and then calculate the no.of vowels in each word and then output the total no. of vowels in the whole sentence, how to do this.

#include <iostream>

using namespace std;
int main ()
{
char string[50];
int count=0;
cout<<"Enter String:";
cin.get(string,50);

for (int j=0;j<51;j++)
{
switch (string[j])
{
case 'a': count++; break;
case 'e': count++; break;
case 'i': count++; break;
case 'o': count++; break;
case 'u': count++; break;
}
}
cout<<"There are "<<count<<" Vovels"<<endl;
}
Try this...!!! :D :P ;)

chinthakapathir
06-02-2009, 12:45 PM
#include <iostream>

using namespace std;
int main ()
{
char string[50];
int count=0;
cout<<"Enter String:";
cin.get(string,50);

for (int j=0;j<51;j++)
{
switch (string[j])
{
case 'a': count++; break;
case 'e': count++; break;
case 'i': count++; break;
case 'o': count++; break;
case 'u': count++; break;
}
}
cout<<"There are "<<count<<" Vovels"<<endl;
}
Try this...!!! :D :P ;)

elakiri boss meka wada gindara wage. thank you sooo sooo much man. needed this so much. thanks. ;) :lol:

¤--bACarDi--¤
06-02-2009, 12:50 PM
elakiri boss meka wada gindara wage. thank you sooo sooo much man. needed this so much. thanks. ;) :lol:

Ow machan matath keywords amathaka wela thibbe.....Elai kaL giye.....
One help ekak illapan.... Puluwan widiyata sup eka dennam....;) :)

chinthakapathir
06-02-2009, 01:09 PM
Ow machan matath keywords amathaka wela thibbe.....Elai kaL giye.....
One help ekak illapan.... Puluwan widiyata sup eka dennam....;) :)

ela kiri machan thanks again.

Issarahatath deffa umbe help one wei. hehe thanks again man.;) :cool::lol: