Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

convert this to C. code: #include<iostream> using namespace std; int main() { in

ID: 3573702 • Letter: C

Question

convert this to C.

code:

#include<iostream>
using namespace std;

int main()
{
   int b1[10]={0};
   int b2[10]={0};
   int score[10]={0};
   int i=0,x1=0,x2=0,flag=0;

   cout<<"Enter scores of ten Frames ";
   for(i=0;i<9;i++)
   {
       cout<<" Frame - "<<i+1<<" ";
       here:cout<<"Ball - 1 : ";
           cin>>b1[i];
           if(b1[i]<0||b1[i]>10)
           {
               cout<<" Illegal score, do one more time... ";
               goto here;
           }

       if(b1[i]==10)
       {
           cout<<" Congratulation! It is STRIKE... ";
           continue;
       }
       cout<<" ";
       label:
       cout<<"Ball - 2 : ";
       cin>>b2[i];
       if(b1[i]+b2[i]>10)
           {
               cout<<" Illegal score, do one more time... ";
               goto label;
           }
       if(b1[i]+b2[i]==10)
       cout<<" Not bad, it is SPARE... ";
       if(b1[i]+b2[i]<10)
       cout<<" Need work harder, Dude! ";

   }

   cout<<" ";
   cout<<" Frame - "<<10<<" ";
   l1:cout<<"Ball - 1 : ";
           cin>>b1[9];
           if(b1[9]<0||b1[9]>10)
           {
               cout<<" Illegal score, do one more time... ";
               goto l1;
           }

       if(b1[9]==10)
       {
           cout<<" Congratulation! It is STRIKE... ";
           flag=1;
       }
       cout<<" ";
           l2:
           cout<<"Extra - 1 : ";
           cin>>x1;
           if(x1==10)
           {
           cout<<" Congratulation! It is STRIKE... ";
           flag=1;
           }
           if((flag==0)&&(b1[9]+x1>10))
           {
               cout<<" Illegal score, do one more time... ";
               goto l2;
           }

       if(b1[9]+x1<10)
       cout<<" Need work harder, Dude! ";

       if(b1[9]+x1==10)
       {
           cout<<" Not bad, it is SPARE... ";
           flag=1;
       }

       if(flag==1)
       {
           cout<<" ";
           l3:
           cout<<"Extra - 2 : ";
           cin>>x2;
           if(x2>10||x2<0)
           {
               cout<<" Illegal score, do one more time... ";
               goto l3;
           }
       }

for(i=0;i<9;i++)
{
   if(b1[i]==10)
   {
       if(i==0)
       {
           score[i]=b1[i]+b1[i+1]+b2[i+1];
       }
       else
       {
           score[i]=score[i-1]+b1[i]+b1[i+1]+b2[i+1];
       }
   }

   else if(b1[i]+b2[1]==10)
   {
       if(i==0)
       {
           score[i]=b1[i]+b2[i]+b1[i+1];
       }
       else
       {
           score[i]=score[i-1]+b1[i]+b2[i]+b1[i+1];
       }
   }
   else
   {
       if(i==0)
       {
           score[i]=b1[i]+b2[i];
       }
       else
       {
           score[i]=score[i-1]+b1[i]+b2[i];
       }
   }
}
score[9]=score[8]+b1[9]+b2[9]+x1+x2;

   cout<<" Frame - 1 2 3 4 5 6 7 8 9 10 Xtr-1 Xtr-2 ";
   cout<<"Ball - 1 : ";
   for(i=0;i<10;i++)
   {
       cout<<b1[i]<<" ";
   }
   cout<<x1<<" "<<x2<<" ";
   cout<<"Ball - 2 : ";
   for(i=0;i<10;i++)
   {
       cout<<b2[i]<<" ";
   }

   cout<<" ";
   cout<<" Score : ";
   for(i=0;i<10;i++)
   {
       cout<<score[i]<<" ";
   }


   return 0;
}

Explanation / Answer

Hi, Please find my modified program.

Please let me know in case of any issue.

#include <stdio.h>

int main()
{
int b1[10]={0};
int b2[10]={0};
int score[10]={0};
int i=0,x1=0,x2=0,flag=0;
  
printf("Enter scores of ten Frames ");
for(i=0;i<9;i++)
{
printf(" Frame - %d ",(i+1));
printf("Ball - 1 : ");
here:
scanf("%d", &b1[i]);
if(b1[i]<0||b1[i]>10)
{
printf(" Illegal score, do one more time... ");
goto here;
}
if(b1[i]==10)
{
printf(" Congratulation! It is STRIKE... ");
continue;
}
printf(" ");
label:
printf("Ball - 2 : ");
scanf("%d", &b2[i]);
if(b1[i]+b2[i]>10)
{
printf(" Illegal score, do one more time... ");
goto label;
}
if(b1[i]+b2[i]==10)
printf(" Not bad, it is SPARE... ");
if(b1[i]+b2[i]<10)
printf(" Need work harder, Dude! ");
}
printf(" ");
printf(" Frame - 10 ");
l1:
printf("Ball - 1 : ");
scanf("%d", &b1[9]);
if(b1[9]<0||b1[9]>10)
{
printf(" Illegal score, do one more time... ");
goto l1;
}
if(b1[9]==10)
{
printf(" Congratulation! It is STRIKE... ");
flag=1;
}
printf(" ");
l2:
  
printf("Extra - 1 : ");
scanf("%d", &x1);
if(x1==10)
{
printf(" Congratulation! It is STRIKE... ");
flag=1;
}
if((flag==0)&&(b1[9]+x1>10))
{
printf(" Illegal score, do one more time... ");
goto l2;
}
if(b1[9]+x1<10)
printf(" Need work harder, Dude! ");
if(b1[9]+x1==10)
{
printf(" Not bad, it is SPARE... ");
flag=1;
}
if(flag==1)
{
printf(" ");
l3:
  
printf("Extra - 2 : ");
scanf("%d", &x2);
if(x2>10||x2<0)
{
  
printf(" Illegal score, do one more time... ");
goto l3;
}
}
for(i=0;i<9;i++)
{
if(b1[i]==10)
{
if(i==0)
{
score[i]=b1[i]+b1[i+1]+b2[i+1];
}
else
{
score[i]=score[i-1]+b1[i]+b1[i+1]+b2[i+1];
}
}
else if(b1[i]+b2[1]==10)
{
if(i==0)
{
score[i]=b1[i]+b2[i]+b1[i+1];
}
else
{
score[i]=score[i-1]+b1[i]+b2[i]+b1[i+1];
}
}
else
{
if(i==0)
{
score[i]=b1[i]+b2[i];
}
else
{
score[i]=score[i-1]+b1[i]+b2[i];
}
}
}
score[9]=score[8]+b1[9]+b2[9]+x1+x2;


printf(" Frame - 1 2 3 4 5 6 7 8 9 10 Xtr-1 Xtr-2 ");
  
printf("Ball - 1 : ");
for(i=0;i<10;i++)
{
printf("%d ", b1[i]);
}
printf("%d %d ", x1, x2);
  
printf("Ball - 2 : ");
for(i=0;i<10;i++)
{
printf("%d ", b2[i]);
}

printf(" ");
  
printf(" Score : ");
for(i=0;i<10;i++)
{
printf("%d ", score[i]);
}

return 0;
}