using a driver function to test my code??
I need to create a function called writeNumber() using the switch statement. The input argument is ch of type char. Now, if ch is not a digit between '0' and '9', then the function returns the value 0 (I can use the isidigit() function). Oherwise, the function writes to the screen the correct English word of the digit charatcer followed by a newline charatcer and has a return value of 1. Once I write the function, I have to use the following driver to test my function:
[CODE]
#include <stdio.h>
#include <ctype>
#include(conio.h>
void main()
{
char c;
int num;
printf("hit any number key>>");
c=(char) getch();
printf("\nYou entered %c>>",c);
num=WriteNumber(c);
if (num==0)
printf("\nThat wasn't a number key\n");
}
[\CODE]
What is a driver function? Do I create my function and then place it below the last } and then try to compile it? I have no idea how to start this. if anybody wants to give me a hint, I would greatly appreciate it. I dont want you to write it for me, I just want to know where to begin. Do I just ignore the driver function and concentrate on my function? Thanks much for your help. I appreciate it... Tommy
can someone check my code
Can someone please see if this program does what it's supposed to do. Earlier, I wrote down what this program is supposed to do. I am not not sure about the returning the value to 0 and the newline character (I did \n as newline character) which has a value of 1????? Thanks for any input. I know this code is sort of mundane, but I have a lot to learn:
Code:
#include <stdio.h>
#include <ctype.h>
#include <conio.h>
int writeNumber(int);
void main() /*DRIVER FUNCTION TO TEST THE FUNCTION*/
{
char ch;
int num;
printf("Hit any number key>>");
ch=(char) getch();
printf("\nYou entered %c>>",ch);
num=writeNumber(ch);
if (num==0)
printf("\nThat wasn't a number key!\n");
}
int writeNumber(int x)
{
int num;
if (isdigit (x)); /* while input equals a number */
switch (x)
{
case '0':
printf("Zero\n");
break;
case '1':
printf("One\n");
break;
case '2':
printf("Two\n");
break;
case '3':
printf("Three\n");
break;
case '4':
printf("Four\n");
break;
case '5':
printf("Five\n");
break;
case '6':
printf("Six\n");
break;
case '7':
printf("Seven\n");
break;
case '8':
printf("Eight\n");
break;
case '9':
printf("Nine\n");
break;
default: /* If user types anything but a number, x = 0 */
x=0;
num=x; /*assigns user input to num*/
return (num); /*num is = to the function, returning num back to function */
}
}