Home > Back-end >  C language for help!
C language for help!

Time:09-18

How to remove goto and add more than one function?

CodePudding user response:

Is a function, the new rules in the goto statement calling function place

For example:
Goto test;
Test:
Pass:

Instead of
Int test () {
Pass
}

test();

CodePudding user response:

reference 1/f, 5250 response:
is a new rule, a function, where a goto call function

For example:
Goto test;
Test:
Pass:

Instead of
Int test () {
Pass
}

test();

After the change of choose function contains the following switch statement

CodePudding user response:

Suggest post pictures ~ code rather than directly

CodePudding user response:

# include & lt; stdio.h>
# include & lt; Stdlib. H>
# include & lt; Time. H>
# include & lt; Ctype. H>
# include & lt; String. H>
//This is a program that will help elementary school school pupils practice math.

Int main ()
{
Char fid [10], ID [10], symbol [10], the convert [3], answer [10] [3].
Int j=0, I, op, n, a [10], [10], b result [10], score=0, grade, timeduation;
The FILE * data;
Time_t tstart, tend;

Do {
Printf (" both Please input your four digit ID number to the as AB1234: ");
The scanf (" % s ", ID);
if(! (ID [6]=='\ 0' & amp; & Isalpha (ID [0]) & amp; & Isalpha [1] (ID) & amp; & Isdigit (ID [2]) & amp; & Isdigit (ID [3]) & amp; & Isdigit (ID [4]) & amp; & [5] isdigit (ID)))
Printf (" Sorry, invalid ID. ");
} while (! (ID [6]=='\ 0' & amp; & Isalpha (ID [0]) & amp; & Isalpha [1] (ID) & amp; & Isdigit (ID [2]) & amp; & Isdigit (ID [3]) & amp; & Isdigit (ID [4]) & amp; & [5] isdigit (ID)));//To check the ID invalidation

Choose:
Printf (" \ nPlease type in the number to continue. (1) to Start a test \ n \ n (2) Check scores \ n (3) the Exit \ n ");
The scanf (" % d ", & amp; op);
The switch (op)//let the user to choose what function they want
{
Case 1:
getchar();
printf("\n");
Srand ((unsigned) time (NULL));
Time (& amp; Tstart);
for(i=0; I<10; I++)//to start the test
{
N=rand () % 4;
Do {
A [I]=rand () % 100;
B [I]=rand () % 100;
The switch (n) {
Case 0: symbol [I]='+';
The result of [I]=[I] a [I] + b;
break;
Case 1: symbol [I]='-';
The result of [I]=[I] a [I] - b;
break;
Case 2: symbol [I]='*';
The result of [I]=[I] a [I] * b;
break;
Case 3: symbol [I]='/';
The result of [I]=[I] a [I]/b;
}
} while (result [I] & gt; 99 | | result [I] <0 | | n==3 & amp; & [I] a [I] % b!=0);
Printf (" % d % 2 c % 2 d=", [I], a symbol [I], [I] b);
Itoa (result [I], convert, 10);
Gets (answer [I]);//gather the user 's answers
if (! STRCMP (convert, answer [I]) {
Score +=10;
}
}
Time (& amp; Tend);//time ends
Printf (" \ nYou have got % d score (s) % ld in seconds! \ n ", score, tend to tstart);
Printf (" Prob. | Correct Answ. | Ur Answ \ n ");//print the test information
for(i=0; I<10; I++)
{
Printf (" % (2 d) % 2 c % 2 d=% d % 3 d % s \ n ", I + 1, a [I], symbol [I], [I], b result [I], answer [I]);
}
Data=https://bbs.csdn.net/topics/fopen (" record. TXT ", "a +");
Fprintf (data, "% s % 3 d % 3 ld \ n", ID, score, tend to tstart);
The fclose (data);
Goto choose;
break;
Case 2:
data=https://bbs.csdn.net/topics/fopen (" record. TXT ", "r");
If (data=https://bbs.csdn.net/topics/=NULL)
{
Printf (" You have never done the test before. ");
Goto choose;
}
Fscanf (data, "% s % d % d", fid, & amp; Grade, & amp; Timeduation);//scan the user 's information
Printf (" Your previous records are: \ n ");
while(! The feof (data))
{
If (STRNCMP (ID, fid, 6)==0)//check the user 's name
{
Printf (" % s % d % d \ n \ n ", fid, grade, timeduation);
j=1;
}
Fscanf (data, "% s % d % d", fid, & amp; Grade, & amp; Timeduation);
}
If (j==0)
{
Printf (" Sorry, there is no previous record. \ n ");
}
The fclose (data);
Goto choose;
break;
Case 3:
Printf (" It 's about to quit! \n");
break;//the quit
Default:
Printf (" Wrong Number! ");
Goto choose;
}
return 0;
}

CodePudding user response:

refer to the second floor weixin_46824808 response:
Quote: reference 1/f, 5250 response:
is a new rule, a function, where a goto call function

For example:
Goto test;
Test:
Pass:

Instead of
Int test () {
Pass
}

test();

After the change of choose function contains the following switch statement it


What's your choose function function, a function of the new rules is what function,
  • Related