I want to make the program that inputs the point of the test though it is sudden.
Though this can be easily achieved by the current having come
When it makes a mistake in a point that is larger than 100 points further this time and it inputs it
Apply the function of automatically correcting to 100 points and memorizing it.
This program is not difficult so much.
The following program is an example of achieving processing ahead.
The result when this program is executed and 100 or less is input becomes as follows.#include <stdio.h> int main(void) { int score; Printf ("Input the point"); scanf("%d",&score); if (score > 100) score = 100; printf(It is "%d point point. \n",score); return 0; }
The result when this program is executed and input that is larger than 100 is done becomes as follows.
Input the point: 58 The input data.
The point It is 58 points.
Here, when further another one input point is larger than 100 points
Input the point: 135 The input data.
The point It is 100 points.
Naturally, it doesn't go well even if the printf sentence ties just behind an existing if sentence.
In the if sentence, the if sentence because only a certain sentence is used for the judgment result as follows soon
Every time, the printf sentence written just behind the if sentence is executed as a usual sentence.
One method is to use two if sentences. As follows
If two if sentences are used, it becomes possible to display the message.if (score > 100) printf("The input : Correct it because it is larger than 100. \n"); if (score > 100) score = 100;
Though two or more sentences can be executed for one condition if it makes it like the foregoing paragraph
In C language, the function to group two or more sentences exists.
It is a function that is called it a block sentence (complex sentence).
It is possible to put two or more sentences on the place where only one sentence can be put or to do by using this block sentence.
[ Block sentence ]
Enclose..two or more..sentence..bring together..method.
If the block sentence is used, two or more processing can be executed by the result of the if sentence.
The following program adds the message display function by using the block sentence.
The result when this program is executed and 100 or less is input becomes as follows.#include <stdio.h> int main(void) { int score; Printf ("Input the point"); scanf("%d",&score); if (score > 100) { printf(" The input : Correct it because it is larger than 100. \n"); score = 100; } printf(It is "%d point point. \n",score); return 0; }
The result when this program is executed and input that is larger than 100 is done becomes as follows.
Input the point: 58 The input data.
The point It is 58 points.
Input the point: 135 The input data.
The input Correct it because it is larger than 100.
The point It is 100 points.