Question

In: Computer Science

Need this C++ code to be modified to work in C, still using 2d arrays... #include...

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...

Solutions

Expert Solution

#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:

.


Related Solutions

I NEED THIS CODE FOR C++ USING MONITORS PLEASE #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include...
I NEED THIS CODE FOR C++ USING MONITORS PLEASE #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <pthread.h> #define THREADS 10 // Number of Thread //bridge declared with array of character and integer value void Bridge(char array[], int value); // Global Variable int North = 1; //For North Number int South = 1; //For South Number pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER; // Setting Up MUTEX for lock //Thread for North farmer void NorthFarmer(){ pthread_mutex_lock(&mutex1); char array[5] = "North"; // North printf("%s Tunbridge...
C++ Make a Tic Tac Toe game for 2 players to play using 2D arrays and...
C++ Make a Tic Tac Toe game for 2 players to play using 2D arrays and classes. Do not add more #include functions other than the ones listed. I never said what type of code I needed in a previous question. I apologize and I can't go back and change it so here is the same question with more information Using the tictactoeGame class, write a main program that uses a tictactoeGame to implement a game in which two players...
C++ CODE ONLY Using the following code. #include <iostream> #include <string> #include <climits> #include <algorithm> using...
C++ CODE ONLY Using the following code. #include <iostream> #include <string> #include <climits> #include <algorithm> using namespace std; // M x N matrix #define M 5 #define N 5 // Naive recursive function to find the minimum cost to reach // cell (m, n) from cell (0, 0) int findMinCost(int cost[M][N], int m, int n) {    // base case    if (n == 0 || m == 0)        return INT_MAX;    // if we're at first cell...
First assignment for C++. How do I setup this dynamic multiplication table using 2D arrays and...
First assignment for C++. How do I setup this dynamic multiplication table using 2D arrays and double pointers? The assignment asks to Write a program that displays a 2D multiplication table based on row and column value specified by the user. Perform a data validation to ensure the number of rows and columns given by the user exist on the interval [1, 10]. If possible, protect against inputs that contain symbols that would normally crash the program (i.e. letter, symbols,...
C++ code Why my code is not compiling? :( #include <iostream> #include <iomanip> #include <string> using...
C++ code Why my code is not compiling? :( #include <iostream> #include <iomanip> #include <string> using namespace std; const int CWIDTH = 26; int main() {    int choice;    double convertFoC, converCtoF;    double starting, endvalue, incrementvalue;    const int CWIDTH = 13;    do {       cin >> choice;    switch (choice)    {        cin >> starting;    if (starting == 28){       cout << "Invalid range. Try again.";    }    while (!(cin >> starting)){       string  garbage;       cin.clear();       getline(cin, garbage);       cout << "Invalid data Type, must be a number....
JAVA I need to write a code that calculates mean and standard deviation using arrays and...
JAVA I need to write a code that calculates mean and standard deviation using arrays and OOP. This is what I have so far. I'm close but my deviation calculator method is throwing errors. Thanks so much :) import java.util.Scanner; import java.util.Arrays; public class STDMeanArray { private double[] tenUserNums = new double[10];//Initialize an array with ten index' private double mean; private double deviation; Scanner input = new Scanner(System.in);//create new scanner object /*//constructor public STDMeanArray(double tenUserNum [], double mean, double deviation){...
I need the following C code converted to java or C++ #include <stdio.h> #include <stdlib.h> typedef...
I need the following C code converted to java or C++ #include <stdio.h> #include <stdlib.h> typedef struct node { struct node *left; struct node *right; long data; long leftSize; } node; void btreeInsert(node *new, node **rootptr) { node *parent = NULL, *cursor; /* Find parent */ cursor = *rootptr; while (cursor != NULL) { parent = cursor; if (new->data < cursor->data) { cursor->leftSize += 1; cursor = cursor->left; } else { cursor = cursor->right; } } /* Insert node below...
C++ Simple Programming Assignment you need to build off of the code below: #include using namespace...
C++ Simple Programming Assignment you need to build off of the code below: #include using namespace std; // class definition class Fraction {         // two data members         // one representing numerator         int numerator;         // other, representing denominator         int denominator;         public:                 void set (int numerator, int denominator);                 Fraction addedTo (Fraction f);                 Fraction subtract (Fraction f);                 Fraction multipliedBy (Fraction f);                 Fraction dividedBy (Fraction f);                 bool isEqualTo (Fraction f);                 void print (); }; void Fraction :: set (int numerator, int denominator) {         this...
Need C++ code to be able to run, keep getting a constant value error #include #include...
Need C++ code to be able to run, keep getting a constant value error #include #include #include #include #include #include using namespace std; using namespace std::chrono; int c; void insertionSort(int* arr, int n) { for (int i = 1;i < n;i++) { int v = arr[i]; int j; for (j = i - 1;j > -1;j--) { c++; if (arr[j] > v) { arr[j + 1] = arr[j]; } else { break; } } arr[j + 1] = v; }...
A C++ question: I want to indent the code of this C++ program: #include<iostream> #include<cstring> using...
A C++ question: I want to indent the code of this C++ program: #include<iostream> #include<cstring> using namespace std; int lastIndexOf(char *s, char target) { int n=strlen(s); for(int i=n-1;i>=0;i--) { if(s[i]==target) { return i; } } return -1; } void reverse(char *s) { int n=strlen(s); int i=0,j=n-1; while(i<=j) { char temp=s[i]; s[i]=s[j]; s[j]=temp; i++; j--; } return; } int replace(char *s, char target, char replacementChar) { int len=strlen(s); int total=0; for(int i=0;i<len;i++) { if(s[i]==target) { s[i]=replacementChar; total+=1; } } return total;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT