hey guys i did this program and its not working it worked for a while and then stopped so would someone please tell me whats wrong with it cause i have to do it soon.

#include <conio.h>   
#include <stdio.h>   
#include <stdlib.h>  


void main()
{
    char sentence[50];  
    int vowel_a; 
    int vowel_e; 
    int vowel_i;    
    int vowel_o; 
    int vowel_u; 
    int non_vowels; 

    float total;
    float perc_a;
    float perc_e;
    float perc_i;   
    float perc_o;
    float perc_u;
    float perc_rest;

    vowel_a = vowel_e = vowel_i = vowel_o = vowel_u= non_vowels = 0;    
    printf("Enter your desired sentence: ");    
    scanf("%49[^\n]%c", &sentence);     

    for(int x = 0; sentence[x]!='\0';x++)
    {
        if(sentence[x]=='a')    
            vowel_a++;              
        if(sentence[x]=='e')
            vowel_e++;
        if(sentence[x]=='i')
            vowel_i++;
        if(sentence[x]=='o')    
            vowel_o++;                      if(sentence[x]=='u')
            vowel_u++;
        if(sentence[x]!='a'&&sentence[x]!='e'&&sentence[x]!='i'&&sentence[x]!='o'&&sentence[x]!='u')
            non_vowels++;
    }

    system("cls");

    printf("You Entered: %s\n\n", sentence);

    printf("Number of characters:\n\n");
    printf("a = %d\t", vowel_a);
    printf("e = %d\t", vowel_e);
    printf("i = %d\t", vowel_i);    
    printf("o = %d\t", vowel_o);
    printf("u = %d\t", vowel_u);
    printf("rest = %d\n\n", non_vowels);


    total = vowel_a + vowel_e + vowel_i + vowel_o + vowel_u + non_vowels;


    perc_a = (vowel_a / total) * 100;
    perc_e = (vowel_e / total) * 100;
    perc_i = (vowel_i / total) * 100;   
    perc_o = (vowel_o / total) * 100;
    perc_u = (vowel_u / total) * 100;
    perc_rest = (non_vowels / total) * 100;


    printf("Percentages of total:\n");
    printf("a = %.2f%%  ", perc_a);
    printf("e = %.2f%%  ", perc_e);
    printf("i = %.2f%%  ", perc_i);
    printf("o = %.2f%%  ", perc_o);
    printf("u = %.2f%%  ", perc_u);
    printf("rest = %.2f%%\n\n", perc_rest);

    getch();
}

The question that comes with this program is:

  1. 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%

Edited 3 Years Ago by pyTony: fixed formating

what do u mean by the code tags cause i changed it to int main()
and then it still does

remove %c from scanf...

//scanf("%49[^\n][B]%c[/B]", &sentence);
scanf("%49[^\n]", &sentence);
This article has been dead for over six months. Start a new discussion instead.