hey guys i got a problem with my program i cant get it to work properly.

The question is:
Write a C/C++ program to count the vowels and letters from the keyboard (maximum 50 characters). The string may contain spaces.
Then it prints out the number of occurrences of each of the vowels a, e, i, o and u, the total number of letters, and each of the vowels as an integer percentage of the letter total.

If the input contains
What a beautiful day!

Suggested output format is:
You enterted: What a beautiful day!

Numbers of characters:
a:4 e:1 i:1 o:0 u:2 rest:13

Percentages of total:
a:19.05% e:4.76% i:4.76% o:0.00% u:9.52% rest:61.90%

and this is my program:

#include<stdio.h>
#include<iostream.h> 
#include<stdlib.h> 
#include<string.h> 

void main() 
{ 
	int j,k; 
	float a,e,i,o,u;
	int A,E,I,O,U; 
	char word[50]; 


	printf("Enter First string: ");
	scanf("%49[^\n]%c", word);

    word = strlen(word); 


for(j=0;j<=k;j++)
{ 
    if ('a'==word[j])     
            a++; 

    if ('e'==word[j])     
            e++; 

    if ('i'==word[j])     
            i++; 

    if ('o'==word[j])     
            o++; 

    if ('u'==word[j])     
            u++; 
} 

    printf("You Typed: "); 
    printf("a:%d\t e:%d\t i:%d\t o:%d\t u:%d\t ", a, e, i, o, u); 
   

    printf("Percantage Of Letter:"); 
	A=(a/k)*100;
	E=(e/k)*100;
	I=(i/k)*100;
	O=(o/k)*100;
	U=(u/k)*100;
    printf("a: %f\t e:%f\t i:%f\t o:%f\t u:%f\t", A, E, I, O, U); 

}

Thanxs

<< moderator edit: added [code][/code] tags >>

Okay here goes. You had got your types mixed up and the casting was not done properly. You had assigned floats to integers there by losing information. Also initialize every variable you define. Otherwise you will have unexpected results. I corrected them and basically got it to work. Also I changed the scanf line too. Yours maybe correct, but I prefer this one.

Here is my code. Compare with your program to see the changes I have made,

#include<stdio.h>
#include<iostream> 
#include<stdlib.h> 
#include<string.h> 
using namespace std;

void main() 
{ 
	int j,k; 
	int a = 0,e= 0,i= 0,o= 0,u= 0;
	float A,E,I,O,U; 
	char word[50]; 


	printf("Enter First string: ");
	cin.getline( word, 50, '\n');

	k = strlen(word); 


	for(j=0;j<=k;j++)
	{ 
		if ('a'==word[j]) 
		a++; 

		if ('e'==word[j]) 
		e++; 

		if ('i'==word[j]) 
		i++; 

		if ('o'==word[j]) 
		o++; 

		if ('u'==word[j]) 
		u++; 
	} 

printf("You Typed: "); 
printf("a:%d\t e:%d\t i:%d\t o:%d\t u:%d\t ", a, e, i, o, u); 


printf("Percantage Of Letter:"); 
A=( ( float )a/k)*100;
E=(( float )e/k)*100;
I=(( float )i/k)*100;
O=(( float )o/k)*100;
U=(( float )u/k)*100;
printf("a: %f\t e:%f\t i:%f\t o:%f\t u:%f\t", A, E, I, O, U); 

}

yeah thanxs heaps i got it to work

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.