文字列または整数の入力を許可したいのですが、理解できないようです。これが私がこれまでに持っているものです。
#include <string.h>
#include <stdio.h>
#include <limits.h>
#include <ctype.h>
#include <stdlib.h>
#define maxL 9182
int main() {
char menuOption;
char cmd[10];
// DECLARE FUNCTIONS TO BE USED IN MENU
float circle() {
float numbers;
float calcFloat;
printf("\n\nYou've selected a circle!\n\n");
printf("Enter in a value between 1.00 and 1000.00: ");
scanf("%f%*c",&calcFloat);
printf("You've entered %f\n", calcFloat);
numbers = 2*calcFloat*3.14159;
printf("The circumference of your circle is: %f\n\n\n", numbers);
}
float sphere() {
float sphere;
float calcSphere;
printf("\n\nYou've selected a sphere!\n\n");
printf("Enter in a value between 10.5 and 1024.00: ");
scanf("%f%*c",&calcSphere);
printf("You've entered %f\n", calcSphere);
sphere = (4/3)*calcSphere*calcSphere*calcSphere*3.14159;
printf("The volume of a sphere with your value is: %.2f\n\n\n", sphere);
}
char checkInput(char input) {
if ((strcmp(input, "0") == 0) || (strcmp(input, "zero") == 0)) {
return 0;
}
}
// END OF FUNCTIONS
// CREATE AND SHOW MENU AND RECEIVE INPUT TO DIRECT TO PROPPER FUNCTION.
for (;;) {
printf("Menu: \n"
"(0)Circle\n"
"(1)Sphere\n"
"(2)Palindrome\n"
"(3)Shuffle\n"
"(4)Quit\n");
printf("Select your choice!: ");
scanf("%c", cmd);
switch (checkInput(tolower(cmd))) {
case 0:
circle();
break;
case 1:
sphere();
break;
}
}
// END OF SWITCH STATEMENT AND MENU
}
scanf
ユーザーエラーを減らすために、0または0のいずれかを入力できるようにします。ありがとうございます。