Help me please (I will master C yet!!) . Soon I will have 2 weeks to master the syntax and functions but now I need help.
Right now I cannot even see how the rest of my coding is because when I execute, the program jumps right to the default case of the switch and regardless of input keep doing so. Any help with this (and any and all the error I cannot see or debug because of this) would be appreciated.
Thank you,Code:#include <stdio.h> int addint (int x, int y); int subint (int x, int y); int multint (int x, int y); int divideint (int x, int y); int powerint (int x, int y); int gcdint (int x, int y); int factorial (int x); int main() { int x=0; int y=0; char select; printf("This program will perform one of the following operations \n"); printf("to two numbers based on your selection from the following menu: \n \n"); printf("1. Add two integers. \n"); printf("2. Subtract two intergers. \n"); printf("3. Multiply two integers. \n"); printf("4. Divide two integers. \n"); printf("5. Calculate integer raised to a positive power. \n"); printf("6. Compute greatest common divisor of two integers. \n"); printf("7. Compute the factorial of an integer. \n \n"); printf("To quit the program at any time, please press q or Q. \n \n"); printf("Please enter two integers: \n\n"); scanf("%d", &x); printf("\n "); scanf("%d", &y); printf("\n "); printf("Please choose desired operation from above menu. \n \n"); scanf("%c", &select); while (select != 'q' && select != 'Q') { switch (select) { case '1': printf("The sum of %d and %d is %d.", x, y,addint(x,y)); break; case '2': printf("%d minus %d is %d", x, y, subint(x,y)); break; case '3': printf("%d multiplied by %d is %d", x, y, multint(x,y)); break; case '4': printf(" %d divided by %d is %d", x, y, divideint(x,y)); break; case '5': printf(" %d raised to %d is %d", x, y, powerint(x,y)); break; case '6': printf("The greatest common denominator of %d and %d is %d", x, y, gcdint(x,y)); break; case '7': printf(" The value of the factorial for %d is %d", x, factorial(x)); break; default: printf("Incorrect value entered, please reenter.\n \n "); break; } printf("This program will perform one of the following operations \n"); printf("to two numbers based on your selection from the following menu: \n \n"); printf("1. Add two integers. \n"); printf("2. Subtract two intergers. \n"); printf("3. Multiply two integers. \n"); printf("4. Divide two integers. \n"); printf("5. Calculate integer raised to a positive power. \n"); printf("6. Compute greatest common divisor of two integers. \n"); printf("7. Compute the factorial of an integer. \n \n"); printf("To quit the program at any time, please press q or Q. \n \n"); printf("Please enter two integers: \n\n"); scanf("%d", &x); printf("\n "); scanf("%d", &y); printf("\n "); printf("Please choose desired operation from above menu. \n \n"); scanf("%c", &select); } printf("You have terminated the program."); return 0; } int addint (int x, int y) { return x + y; } int subint (int x, int y) { return x - y; } int multint (int x, int y) { return x * y; } int divideint (int x, int y) { if (y > 0 || y<0) return x/y; else printf("Error - division by O.\n"); } int powerint (int x, int y) { if (y==1) return 1; else if (y<0) printf("You cannot raise a number to a negative power!\n"); else return x * powerint(x, y-1); } int gcdint (int x, int y ) { /* will add this function in */ } int factorial (int x) { if (x >= 0) return x * factorial (x-1); else if (x<0) printf("Error, negative factorial value entered."); }
Signed frustrated but will work through it !!!!![]()



LinkBack URL
About LinkBacks




I used to be an adventurer like you... then I took an arrow to the knee.