jeudi 25 avril 2019

Program to find vowels, If statements not assigning correct values

I have a simple program to find the vowels in a string. The for loop is supposed to iterate through the string and see if the char matches any of the vowels using and if else block but the output is just 100 As.

I tried making them all just ifs but that gave all Us.

#include <stdio.h>

int main()
{
    const int SIZE = 100;

    char str[SIZE] = {"the brown fox\0"};
    char vowels[SIZE];

    for (int i = 0; i <= SIZE; i++) {

        if (str[i] == '97' || '65') {

            vowels[i] = 'a';

        }

        else if (str[i] == '101' || '69' ) {

            vowels[i] = 'e';

        }

        else if (str[i] == '105' || '73') {

            vowels[i] = 'i';

        }

        else if (str[i] == '111' || '81') {

            vowels[i] = 'o';

        }

        else if (str[i] == '117' || '85')  {

            vowels[i] = 'u';

       }

        printf("%c", vowels[i]);

    }

    return 0;
}

Aucun commentaire:

Enregistrer un commentaire