Question: C PROGRAMMING: I'm getting errors for this...how can I fix it? I also need to add a FOR loop so that the program keeps asking

C PROGRAMMING: I'm getting errors for this...how can I fix it? I also need to add a FOR loop so that the program keeps asking to enter an int and char...until you enter -10000 as the int and any character for ch. Please help.

THESE ARE THE INSTRUCTIONS FOR THE QUESTION:

1.2 Implementation

name your program lab2A.c

keep on reading and processing input, until an integer -10000 is read.

use scanf ("%d %c", ..) to read inputs. define a Boolean function isDigit(char c) to determine if c represents a digit. We mentioned in class that ANSI-C does not have a type `boolean, instead it uses 0 to represent false, and use non-zero integer to represent true. So, as a general practice in C, your function should return a non-zero number (usually 1) if c is a digit and returns 0 otherwise. Note that you should NOT use if c=='0' c=='1' c=='2' c=='3' c=='9'. Instead, use the one-statement trick that we discussed in class.

Note that in getting the numerical value of a digit character such as '3', you should NOT use if c=='0' c=='1' c=='2' c=='3' c=='9'. Instead, use the onestatement trick that we discussed in class.

put the definition (implementation) of function isDigit after your main function.

display the prompt and output as shown below.

------------------------------------------------------------------------------------------------

SAMPLE OUTPUT (WE SHOULD GET THIS): Enter an integer and a character separated by blank>12 c Character 'c' does not represent a digit Enter an integer and a character separated by blank>12 9 Character '9' represents a digit. Sum of 12 and 9 is 21 Enter an integer and a character separated by blank>100 8 Character '8' represents a digit. Sum of 100 and 8 is 108 Enter an integer and a character separated by blank>120 ! Character '!' does not represent a digit Enter an integer and a character separated by blank>-10000 a red 340 %

--------------------------------------------------------------------------------------------

#include #include /* function declaration */ int sum(int, int);

int main() { int in; char ch; printf("Enter an integer and a character separated by blank"); scanf("%d %c", &in, &ch);

if (in.isdigit() && ch.isdigit()){ int c = ch-0; int su= sum(in,c); printf("Character '%d' represents a digit. Sum of %d and %d is %d", c, in, c, su);

} else if (in.isdigit() && in != -10000 && ch.isalpha()) { printf("Character '%c' does not represent a digit", ch); } else if (in == -10000 && ch.isalpha()){ return 0; } return 0; } /* function description*/ int sum (int i, int j){ return i+j; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!