|
From: Ray K. <he...@er...> - 2004-06-11 05:28:26
|
Well, for starters, you've got all kinds of funky MIME headers
in your message, and random characters are being displayed in
hexadecimal. *Please* use a mailer that uses plain text like
it's supposed to; this MIME garbage makes it rather difficult
to read your code.
You also don't specify what the program is *supposed* to do, so
I can only guess at what's wrong.
It looks like you're trying to do a graphical dice-roll, in which
case you don't want showone(), showtwo(), etc. to all execute
no matter what, correct?
If so, the problem lies in main() (which should be declared
as an int, by the way).
//MIME garbage cleaned up for readability
> while(ans =3D=3D 'y')
> {
> r =3D randn(6);
> blines(25);
> if(r =3D=3D 1); showone();
> if(r =3D=3D 2); showtwo();
> if(r =3D=3D 3); showthree();
> if(r =3D=3D 4); showfour();
> if(r =3D=3D 5); showfive();
> if(r =3D=3D 6); showsix();
> blines(21);
> ans =3D getans();
> }
The statements of the form, "if (r =3D=3D foo); showbar();" say,
If r =3D=3D foo, execute the statement following, in this case ";"
The way to do this is:
if (r =3D=3D 1) showone();
if (r =3D=3D 2) showtwo();
etc., without a semicolon after the if statements.
Or better:
while (ans =3D=3D 'y') {
r =3D randn(6);
blines(25);
switch(r) {
case 1: showone();
break;
case 2: showtwo();
break;
case 3: showthree();
break;
case 4: showfour();
break;
case 5: showfive();
break;
case 6: showsix();
break;
}
blines(21);
ans =3D getans();
}
There might even be a way to combine the various
showfoo() functions so that you can replace the
entire switch with "shownum(r)", but I'll leave
that to you.
"Randy" <hun...@be...> wrote:
> This is a multi-part message in MIME format.
>
> ------=3D_NextPart_000_001B_01C44F39.77FD0FA0
> Content-Type: text/plain;
> charset=3D"iso-8859-1"
> Content-Transfer-Encoding: quoted-printable
>
> Help whats wrong?
>
> #include <stdio.h>
> #include <stdlib.h>
> =3D20
> void showone();
> void showtwo();
> void showthree();
> void showfour();
> void showfive();
> void showsix();
> int randn();
> char getans();
> void blines();
> main ()
> {
> int r;
> char ans;
> =3D20
> ans=3D3Dgetans();
> =3D20
> while(ans=3D3D=3D3D'y')
> {
> r=3D3Drandn(6);
> blines(25);
> if(r=3D3D=3D3D1); showone();
> if(r=3D3D=3D3D2); showtwo();
> if(r=3D3D=3D3D3); showthree();
> if(r=3D3D=3D3D4); showfour();
> if(r=3D3D=3D3D5); showfive();
> if(r=3D3D=3D3D6); showsix();
> blines(21);
> ans=3D3Dgetans();
> }
> blines(2);
> }
> int randn(int n)
> {
> return rand()%n + 1;
> }
> char getans()
> {
> int ans;
>
> printf("Throw y/n ?");
> ans =3D3D -1;
> while (ans =3D3D=3D3D -1)
> {
> ans=3D3Dgetchar();
> }
> return ans;
> }
> void blines(int n)
> {
> int i;
> =3D20
> for( i=3D3D1 ;i<=3D3Dn ; i++) printf("\n");
> }
>
> void showone()
> {
> printf("\n * \n");
> }
>
> void showtwo()
> {
> printf(" * \n\n");
> printf(" * \n");
> }
>
> void showthree()
> {
> printf(" * \n");
>
> printf(" * \n");
> printf(" *\n");
> }
>
> void showfour()
> {
> printf(" * * \n\n");
> printf(" * * \n");
> }
>
> void showfive()
> {
> printf(" * * \n");
> printf(" * \n");
> printf(" * * \n");
> }
>
> void showsix()
> {
> int i;
>
> for(i=3D3D1 ; i>=3D3D3 ; i++) printf(" * * \n");
> } =3D20
|