scoreboard program

Oct 2, 2008 at 2:37am
Need some help with my c++ program.....

the program should look like this: (using arrays)
Game # : 1 2 3 4 5 6 7 Total Score:
Team 1: 0 0 0 0 0 0 0 0
Team 2: 0 0 0 0 0 0 0 0

Enter Team Number:
Enter Game Number:
Score:

the idea is that when i enter a team and game number and score, the number i typed in score should go to the corresponding game and team number at the top and replace one of the zeros and if i type another score number in the same place again they would add up and display in that place and in the total score and after i would be finished typing the score the numbers that i inputted should clear so i can type more input numbers again, and for example if i would type a team number greater than 3 in the enter team number what would come out would be invalid team for there are only 2 teams and if i enter a game number greater than 7 invalid game would appear and the program should only exit when i type all zeros in the input fields, and it would then display what team wins. Please , if anyone has any revisions or ideas to fix or improve what i have done on my code please notify me ASAP!! =)

heres my code:
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
main()

{
int g[1][7]={1,2,3,4,5,6,7},r,c,r1,c1,r2,c2,...
int t1[1][7]={0,0,0,0,0,0,0};
int t2[1][7]={0,0,0,0,0,0,0};


{
cout<<"Game Number:\t";
for (r=0;r<1;r++)
{
for (c=0;c<7;c++)
{
cout<<g[r][c]<<"\t";
}
}

cout<<"Total Score"<<"\n";

cout<<"\nTeam 1:\t\t";
for (r1=0;r1<1;r1++)
{
for (c1=0;c1<7;c1++)
{
cout<<t1[r1][c1]<<"\t";
x+=t1[r1][c1];
}
cout<<"\t"<<x;
cout<<"\n";
}

cout<<"\nTeam 2:\t\t";
for (r2=0;r2<1;r2++)
{
for (c2=0;c2<7;c2++)
{
cout<<t2[r2][c2]<<"\t";
y+=t2[r2][c2];

}
cout<<"\t"<<y;
}


cout<<"\n\nEnter Team Number:";rep:
cout<<"\n";
cout<<"\nEnter Game Number:";
cout<<"\n";
cout<<"\nEnter Score:";


void clrscr();
gotoxy(19,7);
cin>>tn;
gotoxy(19,9);
cin>>gn;
gotoxy(19,11);
cin>>score;

if(tn==1 && gn==1)
{
gotoxy(17,3);
cout<<score;
}

1 second ago
if(tn==1 && gn==2)
{
gotoxy(25,3);
cout<<score;
}

if (tn==1 && gn==3)
{
gotoxy(33,3);
cout<<score;
}

if (tn==1 && gn==4)
{
gotoxy(41,3);
cout<<score;
}

if (tn==1 && gn==5)
{
gotoxy(49,3);
cout<<score;
}

if (tn==1 && gn==6)
{
gotoxy(57,3);
cout<<score;
}

if (tn==1 && gn==7)
{
gotoxy(65,3);
cout<<score;
}



t1[0][0]=tn;
t1[0][1]=tn;
t1[0][2]=tn;
t1[0][3]=tn;
t1[0][4]=tn;
t1[0][5]=tn;
t1[0][6]=tn;
t1[0][7]=tn;
g[0][0]=gn;
g[0][1]=gn;
g[0][2]=gn;
g[0][3]=gn;
g[0][4]=gn;
g[0][5]=gn;
g[0][6]=gn;
g[0][7]=gn;
}

gotoxy(19,7);
goto rep;
getch();


}
Last edited on Oct 2, 2008 at 2:37am
Oct 2, 2008 at 12:25pm
Hello,

I tried to work through your program but, I have to admit, I failed in understanding everything.

I know that gotxy() is a very nice function. But in your case I strongly suggest not to use it for the following reason:

Debugging gets pretty hard because it is difficult to find out which cin-statement belongs to which cout-statement.
Your code does not become clearer, it gets more complicated.

Now, to your program in whole. The

 
for (r=0;r<1;r++)

is the same as r = 0 because there is no other value r is allowed to have.

1
2
3
4
5
6
t1[0][0]=tn;
(...)
t1[0][6]=tn;
g[0][0]=gn;
(...)
g[0][7]=gn;

Why do you set all values to the same value (tn or gn)?

------
I would suggest the following:

Re-write (if you already have one) the pseudo-code of your program. The pseudo-code consits of short sentences that describe the steps of your software.

Then, after you defined the steps your program has to run through, try to code these steps one by one. If one module (or in that matter part of the code) is working, start with the next one.

You are using arrays, so really use them. Do not use different arrays for each team. Instead, use one two-dimentional-array as you have already tried but not succeeded.
There is no complex idea behind arrays, if you want to enter the score for team one, game six, the corresponding variable would be score[0][5] (c++ starts counting with 0, not with 1, that's why the index is smaller by one).

If you think this concept through, you will find out that setting a score only requires the input of team-number, game-number and the score. There are no if-thens required. You can then set the values directly.

Adding up the values is easy after that as well. Just iterate through the array and add its elements.

It may sound harsh but you would probably be better off starting anew.

And please, use the code brackets for inserting code. It is the icon with --> # <-- on it.

I hope I could point you in the right direction.

int main
Topic archived. No new replies allowed.