nikolas22t
03-28-2005, 05:19 PM
The Problem Is
Write a program to count the vowels and letters in free text given as standard input. Read text a character at a time until you encounter end-of-data.
Then print out the number of occurrences of each of the vowels a, e, i, o and u in the text, the total number of letters, and each of the vowels as an integer percentage of the letter total.
Suggested output format is:
Numbers of characters:
a 3 ; e 2 ; i 0 ; o 1 ; u 0 ; rest 17
Percentages of total:
a 13%; e 8%; i 0%; o 4%; u 0%; rest 73%
I wrote this
/* Program5:
* Print
* Nicholas Tryfonos
* Student Id: S024N0784
* Date: 21 MAR 2005
*/
#include <iostream.h>
#include <stdlib.h>
#include <string.h>
int j,k; //j for loop, k for counter
float a,e,i,o,u;//small letter for no of char
int A,E,I,O,U; // large for percantage
char in [100];
void main()
{
cout<<"Enter A Word Or frace"<<endl;
cin>>in;
k=strlen(in); // counter k take value of the lenght of string
cout<<endl;
for(j=0;j<=k;j++)//loop from 0 to the end of counter
{
if ('a'==in[j])
a++;
if ('e'==in[j])
e++;
if ('i'==in[j])
i++;
if ('o'==in[j])
o++;
if ('u'==in[j])
u++;
}
cout<<"You Typed "<<k<<" Characters, Which Was :"<<endl;
cout<<"a: "<<a<<" e: "<<e<<" i: "<<i<<" o: "<<o<<" u: "<<u<<endl;
cout<<endl;
cout<<"Percantage Of Letter:"<<endl;
cout<<"a: "<< (A=(a/k)*100)<<"% "<<" e: "<< (E=(e/k)*100)<<"% "<<" i: "<<(I=(i/k)*100)<<"% "<<" o: "<<(O=(o/k)*100)<<"% "<<" u: "<<(U=(u/k)*100)<<"% "<<endl;
}
BUT I READS ONLY THE INPUT UNTIL THE FIRST SPACE AND NOT UNTIL THE END OF THE FRACE ANY IDEAS HOW I CAN SOLVE THIS?
Write a program to count the vowels and letters in free text given as standard input. Read text a character at a time until you encounter end-of-data.
Then print out the number of occurrences of each of the vowels a, e, i, o and u in the text, the total number of letters, and each of the vowels as an integer percentage of the letter total.
Suggested output format is:
Numbers of characters:
a 3 ; e 2 ; i 0 ; o 1 ; u 0 ; rest 17
Percentages of total:
a 13%; e 8%; i 0%; o 4%; u 0%; rest 73%
I wrote this
/* Program5:
* Nicholas Tryfonos
* Student Id: S024N0784
* Date: 21 MAR 2005
*/
#include <iostream.h>
#include <stdlib.h>
#include <string.h>
int j,k; //j for loop, k for counter
float a,e,i,o,u;//small letter for no of char
int A,E,I,O,U; // large for percantage
char in [100];
void main()
{
cout<<"Enter A Word Or frace"<<endl;
cin>>in;
k=strlen(in); // counter k take value of the lenght of string
cout<<endl;
for(j=0;j<=k;j++)//loop from 0 to the end of counter
{
if ('a'==in[j])
a++;
if ('e'==in[j])
e++;
if ('i'==in[j])
i++;
if ('o'==in[j])
o++;
if ('u'==in[j])
u++;
}
cout<<"You Typed "<<k<<" Characters, Which Was :"<<endl;
cout<<"a: "<<a<<" e: "<<e<<" i: "<<i<<" o: "<<o<<" u: "<<u<<endl;
cout<<endl;
cout<<"Percantage Of Letter:"<<endl;
cout<<"a: "<< (A=(a/k)*100)<<"% "<<" e: "<< (E=(e/k)*100)<<"% "<<" i: "<<(I=(i/k)*100)<<"% "<<" o: "<<(O=(o/k)*100)<<"% "<<" u: "<<(U=(u/k)*100)<<"% "<<endl;
}
BUT I READS ONLY THE INPUT UNTIL THE FIRST SPACE AND NOT UNTIL THE END OF THE FRACE ANY IDEAS HOW I CAN SOLVE THIS?