Here is my assignment rules, i am stuck and cannot find what it is i am doing wrong. If some one could help me i would appreciate it
* The main routine must be a 'manager' routine, which means
o The function can declare variables
o The function can call other functions
o The function can save return values from functions and pass those values to other functions
o The function must not perform any task other than the management of other functions
o The function may not call any function other than user-defined functions
* All formal parameters are read-only, even if passed by reference. Functions may not modify their formal parameters
* All variables must be block scope variables defined within the function where they are references. No file scope or external variables
* All user-defined functions must have a function declaration (prototype) before the definition of the main function, and all user-defined functions must be defined after the main routine
* All user-defined functions must be highly cohesive and loosely coupled. In other words, you may perform only one task per function.
Here is what i have:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define bufSize 2048
int calculateEval (char *);
int calculateN (char *);
int calculatePNK (char *);
char input (char *);
int main (){
int intVal[10];
char eval,calcN,calcPNK;
char * userInput;
userInput = input();
eval = calculateEval(userInput);
calcN = calculateN(userInput);
calcPNK = calculatePNK(userInput);
scanf("%*c");
return 0;
}
char input (char *){
char userInput [bufSize];
printf("Enter one of the following options: \n\
Q - Quit the program\n\
Eval(<exp>) - Evaluate a simple expression\n\
! - Evaluate an integer factorial\n\
P(n,k) - Count k-permutations of a string of n characters\n\
Enter your option: ");
fgets(userInput,bufSize,stdin);
return userInput[bufSize];
}
int calulateEval (char *){
char userInput [bufSize];
int varA, varB, exprA;
char evalOp;
sscanf (userInput,"Eval(%d%c%d)", &varA, &evalOp, &varB);
switch(evalOp) {
case '+':
exprA = varA + varB;
printf("%d%c%d=%d\n", varA, evalOp, varB, exprA);
break;
case '-':
exprA = varA - varB;
printf("%d%c%d=%d\n", varA, evalOp, varB, exprA);
break;
case '/':
exprA = varA / varB;
printf("%d%c%d=%d\n", varA, evalOp, varB, exprA);
break;
case '*':
exprA = varA * varB;
printf("%d%c%d=%d\n", varA, evalOp, varB, exprA);
break;
case '%':
exprA = varA % varB;
printf("%d%c%d=%d\n", varA, evalOp, varB, exprA);
break;
case '^':
exprA = pow(varA, varB);
printf("%d%c%d=%d\n", varA, evalOp, varB, exprA);
break;
default;
exprA = 0;
printf("?'%c' is not a valid operator", evalOp);
}
return 0;
}
int calculateN (char *){
char userInput [bufSize];
int factorial, idx1, varA;
sscanf(userInput,"!%d",&varA);
factorial = 1.0;
idx1 = 1;
for(idx1 = 1; idx1 <= varA; idx1++) {
factorial = factorial * (float)idx1;
}
printf("%d! = %.0f\n",varA, factorial);
return 0;
}
int calculatePNK (char *){
char userInput [bufSize];
int varA, permutA, varB,factorial, idx1, idx2, factorial2, varN, varK, numPerms,
varNK;
sscanf(userInput,"P(%d %c %d)",&varA, &permutA, &varB);
printf("A string of %d characters has ",exprA);
factorial = 1.0;
idx1 = 1;
for(idx1 = 1; idx1 <= varN; idx1++) {
factorial = factorial * (float)idx1;
}
varNK = varN - varK;
factoral2 = 1.0;
idx2 = 1;
for(idx2 = 1; idx2 <= varNK; idx2++) {
factoral2 = factoral2 * (float)idx2;
}
numPerms = factorial / factoral2;
printf("%d permutations of length %d\n",numPerms,varK);
return 0;
}