I'm sorry I can't really answer your question, but I'm having a hard time reading your code, in part because your indenting is a bit confusing, but primarily because the variable names don't convey any meaning.
Here's a stab at cleaning up the code a bit:
Code:
#include<a:mylib.h>
#include<lvp\matrix.h>
#include<lvp\vector.h>
void DisplayMat(matrix<String> &mat)//Displays integer matrix by rows and columns
{
int a=0;
char mt;
for(int x=0;x<mat.numrows();x++){ //row counter
for(int y=0;y<mat.numcols();y++){ //column counter
cout.setf(ios::right);
cout.width(3);
cout<<mat[x][y]<<" ";
a++;
if(a%5==0) //spacing
cout<<endl;
}
}
}
/*
//bool Pennies(){
//matrix<String>mat(5,6)
// mat[a][b]=h;
// cout<<"(x)";
//}
*/
void main(){
int a,b,o,C,D,E,F,G;
String h,c,d,e,f,g,z;
matrix<String>mat(5,6);
c="puzzle";
d="ball";
e="poster";
f="game";
g="doll";
z="x";
clrscr();
randomize();
cout<<"--Penny Pitch--"<<endl;
for(int x=0;x<mat.numrows();x++){
for(int y=0;y<mat.numcols();y++){
C=0;
D=0;
E=0;
F=0;
G=0;
o=1+random(6);
a=1+random(4);
b=1+random(4);
if(o==1)
h=c;
C++;
if(o==2)
h=d;
D++;
if(o==3)
h=e;
E++;
if(o==4)
h=f;
F++;
if(o==5)
h=g;
G++;
if(C=3)
cout<<"You won a puzzle!"<<endl;
if(D=3)
cout<<"You won a ball!"<<endl;
if(E=3)
cout<<"You won a poster!"<<endl;
if(F=3)
cout<<"you won a game!"<<endl;
if(G=3)
cout<<"you won a doll!"<<endl;
mat[a][b]=h;
}
}
DisplayMat(mat);
// Pennies();
}
Now isn't that a little bit easier on the eyes?
A couple things jump out at me, first of which is:
Code:
if(o==1)
h=c;
C++;
if(o==2)
h=d;
D++;
if(o==3)
h=e;
E++;
if(o==4)
h=f;
F++;
if(o==5)
h=g;
G++;
I'm guessing you meant for C, D, E, F and G to be incremented only if 'o' is the correct value. To do this, you need to enclose the two statements in curly braces.
Code:
if(o==1)
{
h=c;
C++;
}
Now C will only be incremented if o is equal to 1.
Here's another thing that looks like a bug:
Code:
if(C=3)
cout<<"You won a puzzle!"<<endl;
You've used the assignment operator = instead of the equality comparator, ==, and as a result the if statement will always evaluate to true.
The classic example that was used in my college classes was
Code:
if( underAttack = 1 )
{
FireTheMissiles();
}
I'm pretty sure you wouldn't want that to happen, so make sure you're using the right one. An easy way to prevent this from happening is to phrase it this way:
Code:
if( 3 == c )
cout<<"You won a puzzle!"<<endl;
That way, if you make a typo and accidentally put in
the compiler will complain that you can't assign to the number 3 because it isn't a variable.
Now about those variables. h should probably be renamed to something more descriptive, like maybe prizeString (since that's what's being stored in there). As for c, d, e, f, g, z, those should be either similarly renamed, or done away with altogether.
You must admit that it's a lot easier to read
Code:
if( prizeId == 1 )
prizeString = "puzzle";
than
Code:
if( o == 1 )
h = c;
If you plan to use these strings anywhere else, you'll want them in variables, and in that case, just give the variables real names, like puzzleString or gameString, etc.
Try a few of these things and repost your code, and I'll see what I can do about randomizing the field.