Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m trying to write a C program, but have gotten stuck. Here is the question...

ID: 664384 • Letter: I

Question

I'm trying to write a C program, but have gotten stuck. Here is the question...

Using three functions ( main(), converter() and counter() ), write a program that prompts for a numeric input between 0.00 and 99.99, converts the input into words, and counts the occurrences of each letter of the words.

So, I've started and haven't gotten too far. Here is the skeleton...

// function prototypes

void converter( int wholeNumber, int decimalNumber);

void counter( char *string );

int main( void )

{  

    int wholeNumber;

    int decimalNumber;

    // get number from user

    printf( "%s", "Enter a number ( 0.00 to 99.99 ): " );

    scanf( "%d.%d", &wholeNumber, &decimalNumber );

    converter( wholeNumber, decimalNumber );

} // end main

I can't seem to wrap my head around this... I've been sitting here for hours trying different loops, switch statements, etc. The output is supposed to be something like this:

Enter a number ( 0.00 to 99.99 ): 3.87

The number in word form is:

THREE point EIGHTY-SEVEN

The count of letters (excluding "point") is as follows

'e' has 5 occurrences.

'g' has 1 occurrences.

'h' has 2 occurrences.

'i' has 1 occurrences.

'n' has 1 occurrences.

'r' has 1 occurrences.

's' has 1 occurrences.

't' has 2 occurrences.

'v' has 1 occurrences.

'y' has 1 occurrences.

Any help would be greatly appreciated.

Explanation / Answer

Answer:

#include<stdio.h>

void converter( int wholeNumber, int decimalNumber);

void counter( char *string );

int main( void )

{

int wholeNumber;

int decimalNumber;

printf( "%s", "Enter a number ( 0.00 to 99.99 ): " );

scanf( "%d.%d", &wholeNumber, &decimalNumber );

converter( wholeNumber, decimalNumber );

}

void converter( int wholeNumber, int decimalNumber);

{

intwholeNumber={"ONE","TWO","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE"};

intdecimalNumber={"ELEVEN","TWELVE","THIRTEEN","FOURTEEN","FIFTEEN","SIXTEEN","SEVENTEEN","EIGHTEEN","NINTEEN"};

if(wholeNumber>0&&wholeNumber<=10)

{

wholeNumber-wholeNumber;

}

else if (wholeNumber>10&&wholeNumber<20)

{

m=wholeNumber%10;

}

else if(wholeNumber>20&&wholeNumber<100)

{

j=wholeNumber/10;

wholeNumber=wholeNumber%10;

}

}

void counter(char*string)

{

int wholeNumber;

int count;

while (string[wholeNumber] != '')

{

if (string[wholeNumber] >= 'a' && string[wholeNumber] <= 'z')

count[string[wholeNumber]-'a']++;

wholeNumber++;

}

for (wholeNumber = 0; wholeNumber < 26; wholeNumber++)

{

if (count[wholeNumber] != 0)

printf("%c occurs %d times in the entered string. ",wholeNumber+'a',count[wholeNumber]);

}

}