In: Computer Science
Need this C++ code to be modified to work in C, still using 2d arrays...
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
//Implementation of main function
int main()
{
srand(time(NULL));
//Declaration of output,result,i,j,k ,figure as integer type
and
//assign flog with 0
int output[5][5], result[5], i, j, k, figure = 0;
//Display statement
cout << "The classic BINGO cards contains 25 squares arranged
in five vertical" << endl;
cout << "columns and five side to side rows. Each space in
the grid contains a number." << endl;
cout << "A typical BINGO game utilizes number through 1 to
75. The five columns" << endl;
cout << "of the card are called 'B', 'I','N', 'G' and 'O'
from left to right. " << endl;
cout << "Thee center space is usually marked as 'FS' or 'Free
Space', and is considered " << endl;
cout << "automatically filled. The range of printed number
that can appear on the" << endl;
cout << "card is normally restricted by column," <<
endl;
cout << " with the 'B' column only containing number between
1 and 15 inclusive," << endl;
cout << " with the 'I' column containing only 16 through 30,"
<< endl;
cout << " with the 'N' column containing only 31 through 45,"
<< endl;
cout << " with the 'G' column containing only 46 through 60
and" << endl;
cout << " with the 'O' column containing only 61 through 75,"
<< endl;
//Iterate loop
for (i = 0; i < 5; i++) {
//Iterate loop
for (j = 0; j < 5; j++) {
output[j][i] = (rand() % 15) + ((15 * i) + 1);
//decrement k by j - 1
k = j - 1;
//iterate loop
while (k >= 0) {
if (output[k][i] == output[j][i]) {
output[j][i] = (rand() % 15) + ((15 * i) + 1);
//decrement k by j - 1
k = j - 1;
}
//otherwise
else {
//decrement k by 1
k = k - 1;
}
}
}
}
//Initialize output[2][2] with 0
output[2][2] = 0;
//Display statement
cout << "\t\t B \tI N \tG O" << endl;
//Display statement
cout << "\t\t------------------------" << endl;
//assign 0 to i
i = 0;
//Iterate loop
while (i < 5) {
//Display statement
cout << "\t\t|";
//iterate loop
for (j = 0; j < 5; j++) {
if (i == 2 && j == 2) {
//Display statement
cout << " FS |";
}
//otherwise
else if (output[i][j] < 10) {
//Display statement
cout << " " << output[i][j] << " |";
}
//otherwise
else {
//Display statement
cout << " " << output[i][j] << " |";
}
}
//Display statement
cout << "\n\t\t-------------------------\n";
//increment i by 1
i = i + 1;
}
//Display statement
cout << "\nTest by entering 5 unique integers from 0..75 (use
0 for FS) : ";
cin >> result[0] >> result[1] >> result[2]
>> result[3] >> result[4];
//assign 0 to i
i = 0;
//Iterate loop
while (i < 5) {
//assign 0 to figure
figure = 0;
//Iterate loop
for (j = 0; j < 5; j++)
//check output[i][j] is equal to result[j]
if (output[i][j] == result[j]) {
//increment figure by 1
figure = figure + 1;
}
//otherwise
else {
break;
}
//checl figure is equal to 5
if (figure == 5) {
//Display statement
cout << "BINGO winner!\n\n";
break;
}
//increment i by 1
i = i + 1;
}
//iterate loop
for (i = 0; i < 5 && figure != 5; i++) {
//assign 0 to figure
figure = 0;
//iterate loop
for (j = 0; j < 5; j++)
//check output[j][i] is equal to result[j]
if (output[j][i] == result[j]) {
//increment figure by 1
figure = figure + 1;
}
//otherwise
else {
break;
}
//check figure is equal to 5
if (figure == 5) {
//Display statement
cout << "\nBINGO winner!\n\n";
break;
}
}
//check figure is not equal to 5
if (figure != 5) {
figure = 0;
//Iterate loop
for (i = 0, j = 0; i < 5; i++, j++)
//check output[i][j] is equal to result[j]
if (output[i][j] == result[j]) {
//increment figure by 1
figure = figure + 1;
}
//otherwise
else {
break;
}
//check figure is equal to 5
if (figure == 5) {
//Display statement
cout << "\nBINGO winner!\n\n";
}
}
//check figure is not equal to 5
if (figure != 5)
{
//assign 0 to figure
figure = 0;
//iterate loop
for (i = 0, j = 4; i < 5; i++, j--)
//check output[i][j] is equal to result[j]
if (output[i][j] == result[j]) {
//increment figure by 1
figure = figure + 1;
}
//otherwise
else {
break;
}
//check figure is equal to 5
if (figure == 5) {
//Display statement
cout << "\nBINGO winner!\n\n";
}
}
//check figure is not equal to 5
if (figure != 5) {
//Display statement
cout << "\nNo winner.\n\n";
}
return 0;
}
Once again, I just need this code to compile and run in C...
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
//Implementation of main function
int main()
{
srand(time(NULL));
//Declaration of output,result,i,j,k ,figure as integer type and
//assign flog with 0
int output[5][5], result[5], i, j, k, figure = 0;
//Display statement
printf("The classic BINGO cards contains 25 squares arranged in five vertical\n");
printf("columns and five side to side rows. Each space in the grid contains a number.\n");
printf("A typical BINGO game utilizes number through 1 to 75. The five columns\n");
printf("of the card are called 'B', 'I','N', 'G' and 'O' from left to right. \n");
printf("Thee center space is usually marked as 'FS' or 'Free Space', and is considered \n");
printf("automatically filled. The range of printed number that can appear on the\n");
printf("card is normally restricted by column,\n");
printf(" with the 'B' column only containing number between 1 and 15 inclusive,\n");
printf(" with the 'I' column containing only 16 through 30,\n");
printf(" with the 'N' column containing only 31 through 45,\n");
printf(" with the 'G' column containing only 46 through 60 and\n");
printf(" with the 'O' column containing only 61 through 75,\n");
//Iterate loop
for (i = 0; i < 5; i++)
{
//Iterate loop
for (j = 0; j < 5; j++)
{
output[j][i] = (rand() % 15) + ((15 * i) + 1);
//decrement k by j - 1
k = j - 1;
//iterate loop
while (k >= 0)
{
if (output[k][i] == output[j][i])
{
output[j][i] = (rand() % 15) + ((15 * i) + 1);
//decrement k by j - 1
k = j - 1;
}
//otherwise
else
{
//decrement k by 1
k = k - 1;
}
}
}
}
//Initialize output[2][2] with 0
output[2][2] = 0;
//Display statement
printf("\t\t B \tI N \tG O\n");
//Display statement
printf("\t\t------------------------\n");
//assign 0 to i
i = 0;
//Iterate loop
while (i < 5)
{
//Display statement
printf("\t\t|");
//iterate loop
for (j = 0; j < 5; j++)
{
if (i == 2 && j == 2)
{
//Display statement
printf(" FS |");
}
//otherwise
else if (output[i][j] < 10)
{
//Display statement
printf(" %d |", output[i][j]);
}
//otherwise
else
{
//Display statement
printf(" %d |", output[i][j]);
}
}
//Display statement
printf("\n\t\t-------------------------\n");
//increment i by 1
i = i + 1;
}
//Display statement
printf("\nTest by entering 5 unique integers from 0..75 (use 0 for FS) : ");
scanf("%d %d %d %d %d", result[0], result[1], result[2], result[3], result[4]);
//assign 0 to i
i = 0;
//Iterate loop
while (i < 5)
{
//assign 0 to figure
figure = 0;
//Iterate loop
for (j = 0; j < 5; j++)
//check output[i][j] is equal to result[j]
if (output[i][j] == result[j])
{
//increment figure by 1
figure = figure + 1;
}
//otherwise
else
{
break;
}
//checl figure is equal to 5
if (figure == 5)
{
//Display statement
printf("BINGO winner!\n\n");
break;
}
//increment i by 1
i = i + 1;
}
//iterate loop
for (i = 0; i < 5 && figure != 5; i++)
{
//assign 0 to figure
figure = 0;
//iterate loop
for (j = 0; j < 5; j++)
//check output[j][i] is equal to result[j]
if (output[j][i] == result[j])
{
//increment figure by 1
figure = figure + 1;
}
//otherwise
else
{
break;
}
//check figure is equal to 5
if (figure == 5)
{
//Display statement
printf("\nBINGO winner!\n\n");
break;
}
}
//check figure is not equal to 5
if (figure != 5)
{
figure = 0;
//Iterate loop
for (i = 0, j = 0; i < 5; i++, j++)
//check output[i][j] is equal to result[j]
if (output[i][j] == result[j])
{
//increment figure by 1
figure = figure + 1;
}
//otherwise
else
{
break;
}
//check figure is equal to 5
if (figure == 5)
{
//Display statement
printf("\nBINGO winner!\n\n");
}
}
//check figure is not equal to 5
if (figure != 5)
{
//assign 0 to figure
figure = 0;
//iterate loop
for (i = 0, j = 4; i < 5; i++, j--)
//check output[i][j] is equal to result[j]
if (output[i][j] == result[j])
{
//increment figure by 1
figure = figure + 1;
}
//otherwise
else
{
break;
}
//check figure is equal to 5
if (figure == 5)
{
//Display statement
printf("\nBINGO winner!\n\n");
}
}
//check figure is not equal to 5
if (figure != 5)
{
//Display statement
printf("\nNo winner.\n\n");
}
return 0;
}
.
Output:
.