CRICKET OVER AND ITS RUNS CALCULATION PROCESS
// using for loop
//using else if ladder
//color pg formatting detail
Scenario: In this cricket match a team is going to play six overs.At the end of each over announce the score of that over.After each over the next over should be announced .
#include<stdio.h>
void main()
{
int ball,over,run,score=0,total_score;
over=1;//Defaultly set the over is 1
printf("------- T20------2023------\n");
for(over=1;over<=6;over++)
// for over=1 is initialization or entry level .
//over<=6 is the condition -- The program will enter only if that condition is true.otherwise it will exit.
//over++ is the increment operation its work like over+1.This operation is activated when the program enters after checking whether the condition is correct and returns to the top after completion of the program.
{
printf("%d over is starts\n",over);
for(ball=1;ball<=6;ball++)
//We need to know one thing here.
if the program has two for condition.The first for condition is true then it will come in then when the condition in the for condition given inside is true it will do the job it is given for .Now the condition given inside is wrong .Its goes back to the first given for condition.
{
if(ball==1){
printf("Enter the first ball run :");
scanf("%d",&run);
score=run+score;
}
else if(ball==2)
{
printf("Enter the Second ball run :");
scanf("%d",&run);
score=run+score;
}
else if(ball==3)
{
printf("Enter the Third ball run :");
scanf("%d",&run);
score=score+run;
}
else if(ball==4)
{
printf("Enter the Forth ball run :");
scanf("%d",&run);
score=run+score;
}
else if(ball==5)
{
printf("Enter the Fifth ball run :");
scanf("%d",&run);
score=run+score;
}
else if(ball==6)
{
printf("Enter the Sixth ball run :");
scanf("%d",&run);
score=run+score;
}
else{
printf("over is ended\n");
}
}
printf(" \t%d over end runs scored :%d\n",over,score);
system("color 0A");
/*in this program after the first
over scores are added by
the previous
over runs*/
}
printf("\t----------match is ended--------------- .\n The total runs scored\n----------\n %d\n-------------",score);
printf("the total run scored :%d",score);
}
_________________________________________________________________________
NOTE:
// In this program,after the completion of each over,its run is added to the next over.
// if the given runs go above maybe 6 or 7 then it should not be taken as a run.we do not include this condition in this programm.
-----------------------------------------------------------------------------------------------------------------------------
OUTPUT
------- T20------2023------
1 over is starts🏏
Enter the first ball run :1
Enter the Second ball run :1
Enter the Third ball run :2
Enter the Forth ball run :1
Enter the Fifth ball run :2
Enter the Sixth ball run :1
1 over end runs scored :8
2 over is starts🏏
Enter the first ball run :1
Enter the Second ball run :2
Enter the Third ball run :1
Enter the Forth ball run :2
Enter the Fifth ball run :1
Enter the Sixth ball run :2
2 over end runs scored :17
3 over is starts🏏
Enter the first ball run :1
Enter the Second ball run :2
Enter the Third ball run :1
Enter the Forth ball run :2
Enter the Fifth ball run :1
Enter the Sixth ball run :2
3 over end runs scored :26
4 over is starts🏏
Enter the first ball run :1
Enter the Second ball run :2
Enter the Third ball run :1
Enter the Forth ball run :2
Enter the Fifth ball run :1
Enter the Sixth ball run :2
4 over end runs scored :35
5 over is starts🏏
Enter the first ball run :1
Enter the Second ball run :2
Enter the Third ball run :1
Enter the Forth ball run :2
Enter the Fifth ball run :1
Enter the Sixth ball run :2
5 over end runs scored :44
6 over is starts🏏
Enter the first ball run :1
Enter the Second ball run :2
Enter the Third ball run :1
Enter the Forth ball run :2
Enter the Fifth ball run :1
Enter the Sixth ball run :2
6 over end runs scored :53
----------match is ended--------------- .
The total runs scored🏁
-------------the total run scored :53-------------
No comments:
Post a Comment