Hi all,
I've come a little farther in my C studies since my last post, and I decided to try my hand at building a custom function. The code is compiling, but the counters no longer count past 1. I cannot for the life of me figure out the problem. Here is my updated code:
Code:
#include<stdio.h>
#include <ctype.h>
void count(int counter, char symbol) {
counter++;
for (int i = 0; i < counter; i++) {
putchar(symbol);
}
puts("\nPlease enter a letter: ");
}
int main(void) {
char c;
int vowelCount = 0, conCount = 0;
puts("\nPlease enter a letter: ");
do {
if (isalpha(c = getchar()) || c == '0') {
switch (tolower(c)) {
case '0':
puts("\nThank you for counting on me.");
break;
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
count(vowelCount, '*');
break;
default:
count(conCount, '!');
}
}
else if (!isspace(c)) {
puts("\nAny character not in the English alphabet is not an accepted input for this application.\n\nPlease enter a letter: ");
}
} while (c != '0');
return 0;
}
What it should do:
Code:
>>>c
!
>>>u
*
>>>l
!!
>>>8
Any character not in the English alphabet is not an accepted input for this application.
>>>r
!!!
What it does:
Code:
>>>c
!
>>>u
*
>>>l
!
>>>8
Any character not in the English alphabet is not an accepted input for this application.
>>>r
!
Any help appreciated!