|
|
|
#1 (permalink) |
|
New to Overclock.net
|
I am not really a programmer.I don't even know if this code will work. We are suppose to be writing a program to generate bingo. Using a two-dimensional array. The call input is an array of 80 elements. We are reading the bingo cards and bingo calls from an input file. I keep the 2 errors a function-definition is not allowed here before '{' token on line 71 and 88 in the function search and the function check. Here is my code.
#include <iostream> #include <iomanip> #include <fstream> #include <string> void card(int card1[5][5], int call[80],int row, int col); void search(int card1[5][5], int searchkey, int &row, int &col); void check(int card1[5][5], int row, int col); using namespace std; //Declare the input file and the output file ifstream infile1; ifstream indata; ofstream outfile; int main() { //Declaring variables int card1[5][5]; int call[80]; int row, col; int searchkey; card(card1,call,row,col); infile1.close(); indata.close(); outfile.close(); system("pause"); return 0; } void card(int card1[5][5], int call[80],int row, int col) { int i = 0; int searchkey; int count = 0; //count for card number int count1 = 0; //count for total calls read int count2 = 0; //count for covered numbers infile1.open("bingo.dat"); //Reading the numbers into the array infile1 >> card1[row][col]; while(!infile1.eof()) { //Placing the numbers into the columns {for(row = 0; row < 5; row++) //Placing the numbers into the rows for(col =0; col < 5; col++) infile1 >> card1[row][col]; count++; //count for card number } indata.open("calls.dat"); outfile.open("game.txt"); indata >> call[count1]; while(!indata.eof()) { count1++; search(card1,searchkey,row,col); check(card1,row,col); infile1 >> card1[row][col]; } } //searches each column on card for number called void search(int card1[5][5], int searchkey, int &row, int &col) { for(int row = 0; row < 5; row++) { for(int col = 0; col < 5; col++) {searchkey = call[count1]; if(searchkey == card1[row][col]) {row = -2; col = -2; count2++; return; } } } } void check(int card1[5][5], int row, int col) { //check diagonals card1[3][3] = -2; int numsdiag1 = 0; int numsdiag2 = 0; int numscol = 0; int numsrow = 0; {if(card1[row][col] < 0) numsdiag1++; else if(card1[row][4-col] < 0) numsdiag2++; else if(card1[0][col] < 0) numscol++; else if(card1[row][0] < 0) numsrow++; } outfile << "card #" << count << ":" << endl; {if(numsdiag1 == 5) outfile << setw(3) << "BINGO occurs on diagonal 1" << endl; else if(numsdiag2 == 5) outfile << setw(3) << "BINGO occurs on diagonal 2" << endl; else if(numscol == 5) outfile << setw(3) << "BINGO occurs on column"[i] << endl; else if(numsrow == 5) outfile << setw(3) << "BINGO occurs on row"[i] << endl; } outfile << setw(3) << count2 << "items were covered on this card" << endl; outfile << endl; outfile << endl; } } |
|
|
|
|
|
#2 (permalink) | |||||||||||||
|
.
![]() |
I've moved your thread to the coding and programming forum where it will be better suited.
![]()
__________________
... wherever I may roam; where I lay my head is home ... Electricity Explained --- Got a G15? Use ATI Tool? Check this out! --- Compilation of Free Security Utilities --- Rule #1: Obey All Rules --- E2160 @ 3400mhz, Orthos Stable
|
|||||||||||||
|
|
|
|
#3 (permalink) | ||||||||||||
|
WaterCooler
|
I dont have time to really look at it right now but when I compiled it i got 7 errors . . .most being unreferenced local variables. . . Ill try to look at it later after class/practice
__________________
XPS M1330: T7500, 4GB, 13.3" LED WXGA, 128 8400 GS, 120GB 5400RPM, 802.11 AGN, 9 cell, Fingerprint, Ultimate x64, 4 Year Accidental Damage/lojack/warranty. __________________
|
||||||||||||
|
|
|
|
#4 (permalink) | |||||||||||||
|
Apple Doesn't Love You
|
There definitely should not be a bracket before the first 'if' of the check function
|
|||||||||||||
|
|
|
|
#5 (permalink) | ||||||||||||
|
WaterCooler
|
agreed. . . .it should be on the line after it. . .
__________________
XPS M1330: T7500, 4GB, 13.3" LED WXGA, 128 8400 GS, 120GB 5400RPM, 802.11 AGN, 9 cell, Fingerprint, Ultimate x64, 4 Year Accidental Damage/lojack/warranty. __________________
|
||||||||||||
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|