Question

I need a basic program in C to modify my program with the following instructions:

Create a program in C that will:

Add an option 4 to your menu for "Play Bingo"

-read in a bingo call (e,g, B6, I17, G57, G65)

-checks to see if the bingo call read in is valid (i.e., G65 is not valid)

-marks all the boards that have the bingo call

-checks to see if there is a winner, for our purposes winning means 5 tokens in a row or column 5 tokens in a diagonal( diagnols meaning upper right corner to lower left and vice versa) 1 token in each of the 4 corners of the game board

-Loop accepting bingo calls until there is a winner, and display an appropriate message specifying which user won, and how they won (5 in a row with calls B6, I20, ...; 5 in a column with calls ...; 5 on a diagonal with calls ... ; 4 corners with calls ...)

-The program created should have multiple functions here, 1 function that checks for each way of winning (row, column, diagnal, 4 corners)

Here is my program which should include program needed (copy and paste to an IDE) most of the work is done, I just need the four functions per instructions above:

#include #include int main() { int numPlayers = 0; // how many players int cardsPerPlayer = 0;//cards the user inputs per player int rows=5; int col =5; int i=0; int j=0; int k=0; int num=15; srand((int)time(0)); // generating the random seed to make unique cards while (numPlayers>5 || numPlayers<1) { printf("Please enter the number of players: \n"); //user to input the number of players scanf("%d", &numPlayers); if (numPlayers>5 || numPlayers<1) { printf("A maximum of 5 players per game: \n"); } } printf("\n"); while (cardsPerPlayer>10 || cardsPerPlayer<1)//while loop to restrict user input for cards per player { printf("How many cards would you like to generate per player?\n");//user to input the number of cards per player scanf("%d", &cardsPerPlayer); if (cardsPerPlayer>10 || cardsPerPlayer<1) { printf("A maximum of 10 cards per player\n"); } } printf("\n"); int totalPlayerCards; printf("You are playing a game with %d players and each player will have %d cards.\n", numPlayers, cardsPerPlayer); totalPlayerCards=numPlayers * cardsPerPlayer; printf("We have generated %d bingo cards.\n\n", totalPlayerCards);//This indicates total amount of cards generated int bingoBoard[numPlayers][cardsPerPlayer][rows][col] ;//this is my 4 dimensional array // generates the arrays for(i=0; i< numPlayers; i++) // for loop to increment through all the players { for(j=0; j { for(rows=0; rows<5; rows++) // increments through each row { for(col=0; col<5; col++) // increments through each col { if(col==0) // generates the appropriate values for each column { bingoBoard[i][j][rows][col] = (rand()%15)+1; } if(col==1) { bingoBoard[i][j][rows][col] = (rand()%15)+16; } if(col==2) { bingoBoard[i][j][rows][col] = (rand()%15)+31; } if(col==3) { bingoBoard[i][j][rows][col] = (rand()%15)+46; } if(col==4) { bingoBoard[i][j][rows][col] = (rand()%15)+61; } } } } } for(i=0; i { for(j=0; j { for(rows=0; rows<5; rows++) { for(col=0; col<5; col++) { for(k=1; k { while (bingoBoard[i][j][rows][col] == bingoBoard[i][j][rows-k][col]) //it checks the current spot in the array and compares it to the previous values of the column { bingoBoard[i][j][rows][col] = (rand()%15) + (15*col) +1; // if the numbers match then it assigns it a new value } } } } } } //menu of options for the user to select from printf("Please choose an option from the following menu: \n"); printf("1) Display a bingo card\n"); printf("2) run a histogram across all bingo cards generated\n"); printf("3) exit\n"); int menuOptions; while (menuOptions>3|| menuOptions<1) { scanf("%d", &menuOptions); if (menuOptions>3|| menuOptions<1) { printf("That option is not available.\n"); printf("Choose between 1, 2, or 3\n"); } } printf("\n"); printf("You have chosen %d\n", menuOptions); do { if(menuOptions==1) // choice 1 prints a specific card { int player; // user picked player int playerCard; // user defined card int userPlayer=0; int userCard=0; printf("Enter the player and players card you would like to display: \n"); scanf("%d %d", &player, &playerCard); userPlayer = player - player; userCard = playerCard - playerCard; printf("First player is %d, and last player is %d\n", userPlayer, (player-1)); printf("First card is %d, last card is %d\n", userCard, (playerCard-1)); printf("You are viewing player %d's Bingo Card %d\n", player, playerCard); printf("\n"); printf("B\tI\tN\tG\tO\n"); for(rows=0; rows<5; rows++) { for(col=0; col<5; col++) { if(rows==2 && col==2)//this tells program to have a "free" spot in row 2, column 2 { bingoBoard[numPlayers-1][cardsPerPlayer-1][rows][col] = -1; // sets the free spot to -1 as a flag. -1 does not get picked up by the histogram printf("free\t"); col++; // moves to the next spot to continue on with the array } printf("%d\t",bingoBoard[player-1][playerCard-1][rows][col]); } printf("\n"); } } if (menuOptions==2) // choice 2 runs a histogram on all values generated { printf("HISTOGRAM\n"); int l=0; int seen [75] = {0}; // array that counts how many times a value has been seen for(l=1; l<76; l++) // loops through the array { for(i=0 ; i< numPlayers; i++) // { for(j=0 ; j { for(rows=0 ; rows<5; rows++) { for(col=0; col<5; col++) { if(bingoBoard[i][j][rows][col]== l) // if any element in the array matches, l gets incremented { seen[l-1] = seen[l-1] +1; } } } } } printf("%d-%d\t", l, seen[l-1]); // prints out how many times each number has been seen if (l==10)//if l equals 10, a new line will be generated { printf("\n"); } if (l==20)//if l equals 20, a new line will be generated { printf("\n"); } if (l==30)//if l equals 30, a new line will be generated { printf("\n"); } if (l==40)//if l equals 40, a new line will be generated { printf("\n"); } if (l==50)//if l equals 50, a new line will be generated { printf("\n"); } if (l==60)//if l equals 60, a new line will be generated { printf("\n"); } if (l==70)//if l equals 70, a new line will be generated { printf("\n"); } } } printf("\n"); printf("\n"); //asks the user what they want to do next printf("Please choose an option from the following menu: \n"); printf("1) Display a bingo card\n"); printf("2) run a histogram across all bingo cards generated\n"); printf("3) exit\n"); scanf("%d", &menuOptions); printf("You have chosen %d\n", menuOptions); if (menuOptions>3|| menuOptions<1) { printf("That option is not available.\n"); printf("Choose between 1, 2, or 3\n"); } } while(menuOptions != 3); // program quits if user enters 3 printf("Thank you for playing!\n"); printf("Goodbye"); return 0; }

Here is what the output should look like:

Enter the number of players:5 Enter the number of BINGO cards per player:10 You are playing a game with 5 players and each player will have 10 cards We have generated 50 bingo cards. Please choose an option from the following menu: 1) Display a bingo card 2) run a histogram across all bingo cards generated 3) exit 4) Play Bingo! You have chosen 1 Enter the player and players card you would like to display, First player is e, last player is 4 First card is , last card is9 2 0 67 6 27 3 54 68 10 24 free 52 62 65 12 16 33 59 63 51 L AA 17 44 2 26 39 47 Please choose an option from the following menu: 1) Display a bingo card 2) run a histogram across all bingo cards generated 3) exit 4) Play Bingo! 4 You have chosen 4 Enter the called value:I17 read in I 17marking I17 on the boards Enter the called value: 172 read in I 72, Invalid Bingo Call Enter the called value: I27 read in I 27marking I27 on the boards Enter the called value: 124 read in I 24marking I24 on the boards Enter the called value: I62 read in I 62, Invalid Bingo Call Enter the called value: I26 read in I 26marking I26 on the boards Enter the called value: I16 read in I 16marking I16 on the boards we have a winner in column 1 on player 2s card # 2 117 127 124 126 116

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include<iostream>
usingnamespace std;
struct node
{
    int data;
    node *next;
    node *prev;
};
void addnode();
void delnode();
void display();
void show();
void search();
node *start=NULL, *temp1, *temp2, *temp3;
int main()
{ 
    char ch;
    do
    {
        char i;
        cout<<"Press 'a' to add node , 'd' to delete"<<endl;
        cout<<" 's' for search, 'v' for display ,'e' for backward display"<<endl;
        cin>>i;
       switch (i)
       {
       case'a':
          addnode();
          break;
       case'd':
          delnode();
          break;
       case'v' :
          display();
          break;
       case's':
          search();
          break;
       case'e':
           show();
          break;
       default:
          cout<<"Bad input"<<endl;
          break;
       }
       cout<<"want to process more y/n"<<endl;
       cin>>ch;
     }
     while(ch!='n'); 
       return 0;
}
void addnode()          //adding node
{
    char r;
    temp1=new node;
    cout<<"enter int to store"<<endl;
    cin>>temp1->data;
    cout<<"press 's' to add in start,'m' for midd , 'e' for end"<<endl;
    cin>>r;
    switch (r)
    {
    case's':                 //add startif(start==NULL)
        {
            start=temp1;
            temp1->next=NULL;
            temp1->prev=NULL;
        }
        else
        {
            temp2=start;
            temp1->next=temp2;
            temp1->prev=NULL;
            start=temp1;
            temp2->prev=temp1;
        }
        break;
    case'e':               //add endif(start==NULL)
        {
            start=temp1;
            temp1->next=NULL;
            temp1->prev=NULL;
        }
        else
        {
            temp2=start;
            while(temp2->next!=NULL)
                temp2=temp2->next;
            temp2->next=temp1;
            temp1->prev=temp2;
            temp1->next=NULL;
        }  
        break;
    case'm':                //add midint num;
        cout<<"enter node after which you want to enter"<<endl;
        cin>>num;
        temp2=start;
        for(int i=0;i<num;i++)
        {
            if(start==NULL)
                cout<<"given node not found"<<endl;
            else
            {
               temp3=temp2;
               temp2=temp2->next;
               
            }
        }
         temp1->next=temp2;
         temp3->next=temp1;
         temp1->prev=temp3;
         temp2->prev=temp1;
        break;
    }
}
void display()        //displaying
{
   
    temp3=start;
    if(start==NULL)
        cout<<"no node to display"<<endl;
    else
    {
      while(temp3->next!=NULL)
      {
          cout<<"Data stored is "<<temp3->data<<" at "<<temp3<<endl;
         temp3=temp3->next;
      }
      cout<<"Data stored is "<<temp3->data<<" at "<<temp3<<endl;
    }
}

void search()            //searching
{   
    int p;
    cout<<"enter no to search"<<endl;
    cin>>p;
    temp1=start;
    while(temp1->next!=NULL)
    {
        if(temp1->data==p)
        {
            cout<<temp1->data<<" is stored in "<< temp1->next<<endl;
        }
        temp1=temp1->next;
    }
}
void delnode()           //deleting
{  
    
    char d;
    cout<<"press 's' to delete from start,'m' for midd , 'e' for end"<<endl;
    cin>>d;
    switch (d)
    {
      case's':               //delete startif(start==NULL)
          {
              cout<<"no node to delete"<<endl;
          }
          else
          {
              temp1=start;
              start=start->next;
              start->prev=NULL;
              delete temp1;
          }
         break;
      case'e':            //delete endif(start==NULL)
          {
              cout<<"no node to delete"<<endl; 
          }
         else
         {
             temp1=start;
             while(temp1->next!=NULL)
             {
                temp2=temp1;
                temp1=temp1->next;
             }
              delete temp1;
             temp2->next=NULL;
         }
        break;
      case'm':               //delete midint num;
          cout<<"enter node you want to delete"<<endl;
          cin>>num;
          
          temp1=start;
          for(int i=1;i<num;i++)
          {
              if(start==NULL)
               cout<<"given node does not exist"<<endl;
              else
              {
                temp2=temp1;
                temp1=temp1->next;
              }
          }
          temp3=temp1->next;
          temp2->next=temp3;
          temp3->prev=temp2;
          delete temp1;
          break;
    }
}
void show()               //backward display
{
    cout<<"backward display"<<endl;
    temp3=start;
    if(start==NULL)
        cout<<"no node to display"<<endl;
    else
    {
       while(temp3->next!=NULL)
       {
           temp3=temp3->next;
       }
       while(temp3->prev!=NULL)
       {
           cout<<"Data stored is "<<temp3->data<<" at "<<temp3<<endl;
           temp3=temp3->prev;
       }
       cout<<"Data stored is "<<temp3->data<<" at "<<temp3<<endl;
    }
}
Add a comment
Know the answer?
Add Answer to:
I need a basic program in C to modify my program with the following instructions: Create...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Can someone tell me why this is not printing in the screen. I know i commented...

    Can someone tell me why this is not printing in the screen. I know i commented out the first couple functions but the last one is not working. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- #include <stdio.h> #include <stdlib.h> #include <time.h> #define ROWS 5 #define COLS 5 #define FREE 2 #define SCALE 15 #define SHIFT 1 #define MAXVAL 75 #define FALSE 0 #define TRUE 1 void welcomeScreen(); void clearScreen(); void displayExplicitCard(); void displayCard(); void displayRandomCard(); void fillCardRand(); void setValue(); void displayBingoCard(); void initializeArrays (); int main...

  • I am trying to add a string command to my code. what am i doing wrong?...

    I am trying to add a string command to my code. what am i doing wrong? #define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include <stdio.h> #include <string.h> #include <math.h> int main(void) {    int i, j;    int rowA, colA, rowB, colB;    int A[10][10], B[10][10];    int sum[10][10];    char str1[10];    printf("This is a matrix calculator\n");    //read in size from user MATRIX A    printf("Enter in matrix A....\n");    printf("\t#row = ");    scanf("%d", &rowA);    printf("\t#col = ");   ...

  • So I have a question in regards to my program. I'm learning to program in C...

    So I have a question in regards to my program. I'm learning to program in C and I was curious about the use of functions. We don't get into them in this class but I wanted to see how they work. Here is my program and I would like to create a function for each of my menu options. I created a function to display and read the menu and the option that is entered, but I would like to...

  • Missing multiple labeled functions. Card matching game in C. Shouldn't need any more functions. I am...

    Missing multiple labeled functions. Card matching game in C. Shouldn't need any more functions. I am lost on how to complete the main function (play_card_match) without the sub functions complete. The program runs fine as is, but does not actually have a working turn system. It should display question marks on unflipped cards when the player is taking a turn and should also clear the screen so the player can't scroll up to cheat. Thank you #include "cardMatch.h" //main function /*...

  • C Programming The following code creates a deck of cards, shuffles it, and deals to players....

    C Programming The following code creates a deck of cards, shuffles it, and deals to players. This program receives command line input [1-13] for number of players and command line input [1-13] for number of cards. Please modify this code to deal cards in a poker game. Command line input must accept [2-10] players and [5] cards only per player. Please validate input. Then, display the sorted hands, and then display the sorted hands - labeling each hand with its...

  • Please help modify my C program to be able to answer these questions, it seems the...

    Please help modify my C program to be able to answer these questions, it seems the spacing and some functions arn't working as planeed. Please do NOT copy and paste other work as the answer, I need my source code to be modified. Source code: #include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> int main(void) { char title[50]; char col1[50]; char col2[50]; int point[50]; char names[50][50]; printf("Enter a title for the data:\n"); fgets (title, 50, stdin); printf("You entered: %s\n", title);...

  • C++ HELP I need help with this program. I have done and compiled this program in...

    C++ HELP I need help with this program. I have done and compiled this program in a single file called bill.cpp. It works fine. I am using printf and scanf. Instead of printf and scanf use cin and cout to make the program run. after this please split this program in three files 1. bill.h = contains the class program with methods and variables eg of class file class bill { } 2. bill.cpp = contains the functions from class...

  • Need help with this C program? I cannot get it to compile. I have to use...

    Need help with this C program? I cannot get it to compile. I have to use Microsoft Studio compiler for my course. It's a word game style program and I can't figure out where the issue is. \* Program *\ // Michael Paul Laessig, 07 / 17 / 2019. /*COP2220 Second Large Program (LargeProg2.c).*/ #define _CRT_SECURE_NO_DEPRECATE //Include the following libraries in the preprocessor directives: stdio.h, string.h, ctype.h #include <stdio.h> /*printf, scanf definitions*/ #include <string.h> /*stings definitions*/ #include <ctype.h> /*toupper, tolower...

  • Debug the following matrix program in C: // Program to read integers into a 3X3 matrix...

    Debug the following matrix program in C: // Program to read integers into a 3X3 matrix and display them #include <stdio.h> void display(int Matrix[3][3],int size); int main(void) {         char size;         double Matrix[size][size+1];         printf("Enter 9 elements of the matrix:\n");         int i;         for (i = 0: i <= size: i++)     {       int j = 0;       for (; j <= size++; j++){         scanf("%d", matrix[i--][4])       }     }         Display(Matrix,9);         return 0; void...

  • I am trying to figure out why my C code is outputting "exited, segmentation fault". The...

    I am trying to figure out why my C code is outputting "exited, segmentation fault". The game is supposed to generate 4 random numbers and store them in the "secret" array. Then the user is suppose to guess the secret code. The program also calculates the score of the user's guess. For now, I printed out the random secret code that has been generated, but when the game continues, it will output "exited, segmentation fault". Also, the GetSecretCode function has...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT