求指教~ 两个没有很大差别的程序 一个可以运行,另一个就中断
可以运行的程序在这里~程序代码:
#include <stdio.h> #include <ctype.h> int main() { char num[6]; int i,a=0,b=0; printf("Please input your ID number:\n(including two letters & 4 digits)\n"); for (i=0; i<6; i++) scanf("%c", &num[i]); for (i=0; i<2; i++) { if(isalpha(num[i])) a++; } for (i=2; i<6; i++) { if(isdigit(num[i])) b++; } if (a!=2 || b!=4 ) printf("Wrong!"); else printf("Please choose an option:\n(1) Start a test\n(2) Check scores\n(3) Exit\n"); return 0; }
这个程序就不能运行。。。(这只是一部分啦,剩下的还在编,这一部分无法运行。。)
程序代码:
#include <stdio.h> #include <time.h> #include <stdlib.h> #include <ctype.h> int main() { int i, a=0, b=0, option; char no[6]; printf( "This program will help elementary school pupils practice math.\n" ); printf( "Please input your ID number:\n(including two letters and four digits)\n" ); /*Check the ID number*/ for (i=0; i<6; i++) scanf("%c", no[i]); for (i=0; i<2; i++) { if (isalpha (no[i])) a++; } for (i=2; i<6; i++) { if (isdigit (no[i])) b++; } if (a !=2 || b !=4) printf("PLease check your ID number and run again.\n"); /*start the program*/ else { printf("PLease input a number less than 4 to choose an option:\n(1)Start a test\n(2)Check scores\n(3)Exit"); scanf("%d",&option); do { printf("Oh, please choose it again"); } while (option<4); switch(option) { case 1: printf("yeah"); break; case 2: printf("wrong"); break; case 3: return 0; break; } } return 0; }