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

  • In need of some help with a LCR C++ game. The code will run, but I...

    In need of some help with a LCR C++ game. The code will run, but I need it to cycle through the turns automatically so that the only input from the user is the number of players. It's also showing the winner as the person with 0 chips which is incorrect and I can't figure out why. Any help is greatly appreciated as this is already late. Game rules: Develop a program that follows the rules of Left Center Right...

  • 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);...

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

  • Need done in C++ Can not get my code to properly display output. Instructions below. The...

    Need done in C++ Can not get my code to properly display output. Instructions below. The code compiles but output is very off. Write a program that scores the following data about a soccer player in a structure:            Player’s Name            Player’s Number            Points Scored by Player      The program should keep an array of 12 of these structures. Each element is for a different player on a team. When the program runs, it should ask the user...

  • Can anyone help me with my C++ assignment on structs, arrays and bubblesort? I can't seem...

    Can anyone help me with my C++ assignment on structs, arrays and bubblesort? I can't seem to get my code to work. The output should have the AVEPPG from highest to lowest (sorted by bubbesort). The output of my code is messed up. Please help me, thanks. Here's the input.txt: Mary 15 10.5 Joseph 32 6.2 Jack 72 8.1 Vince 83 4.2 Elizabeth 41 7.5 The output should be: NAME             UNIFORM#    AVEPPG Mary                   15     10.50 Jack                   72      8.10 Elizabeth              41      7.50 Joseph                 32      6.20 Vince                  83      4.20 ​ My Code: #include <iostream>...

  • I need this done in C++ Can someone help me get my code from crashing. The...

    I need this done in C++ Can someone help me get my code from crashing. The code compiles but it can be easily crashed with user input. The rubric and code below Instructions: Write a program that scores the following data about a soccer player in a structure:            Player’s Name            Player’s Number            Points Scored by Player      The program should keep an array of 12 of these structures. Each element is for a different player on a...

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