Array display problem - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Array display problem

madjmmadjm Posts: 2Member
Here is a program i have the the problem with it is that the array totalwin[5] via (totalwin[cnt]) is displaying some weird figures on the first display it also displays the correct figure on the final display but to 6 decimal places.


what am i doing wrong and how can i fix this ?

[code]
#include
#include
#include

int main (void)

{ // Begin //

// Variables//
int choice,result,play1=38000,play2=38000,pbet;
int cnt = 0 , cnt2 =0 ;

char fname[15],mname[15],lname[15],c;
float amtwon,amtlost,totalwin[5],doublebet,avgwin,ovwin=0;



// User chooses their country's desgenation//
printf("
Enter 1 for first world country !
");
printf(" Enter 2 for second world country !
");
printf(" Enter 3 for thrid world country !
");
printf("
Choose where you are from: ");
scanf ( "%d",&choice);

// This while loop ensures an error message will come up unless the right values are entered

while ( choice < 1 || choice >3)
{
printf(" Error please choose a number from the list above ");
scanf("%d",&choice);
}
system("cls");


// If esle statement code that notives the user of their selection//
if (choice==1)
{
printf("

You are from a first world country");
}
else
{
if (choice==2)
{
printf("

You are from a second world country");
}
else
if (choice==3)
{
printf("

You are from a thrid world country");
}

else
printf(" ");
}
// User is asked to imput their information//
printf("
Enter your first name :");
scanf("%s",fname);

printf("
Enter your middle name: ");
scanf("%s",mname);

printf("
Enter your last name: ");
scanf("%s",lname);


system("cls");


do {
// Begining of restart loop//
// If the user choses to restart the program,it will begin from here//
printf( "
Enter the amount you want to bet: ");
scanf ("%d",&pbet);


// This while loop ensure's that the user does not enter 0 or a negative value//
while ( pbet <= 0)
{
printf(" Error please enter a suitable bet amount ");
scanf("%d",&pbet);
}
// begining of case, all calculations and output done based on user input//
switch (choice)
{
case 1: //First world country calulations//

amtwon= ((pbet*pbet) / (pbet* pbet* pbet)) * 30500;
amtlost= (pbet * 0.35);
totalwin[cnt2]= ( amtwon - amtlost);
avgwin = (play1 + play2 + totalwin[cnt2]) / 3;
ovwin = ovwin + totalwin[cnt2];

cnt2 ++ ;

//This clears the screen to make everything more neat and tidy//

system("cls");//Endures that this out put is not repeated line by line//

printf("
Player Name : %s %s %s" ,fname,mname,lname );
printf("
Amount Won is : $JA %6.2f ",amtwon);
printf("
Amount Lost : $JA %1.f",amtlost);

// [b]Here is the display problem[/b]//
printf("
Total winnings : $JA %6.2f",totalwin[cnt2]);
printf("
Average Total Winnings : $JA %6.2f",avgwin);

// This message will come up if the user's bet is doubled//
if (totalwin[cnt2]> pbet+pbet)
{ printf("


Congratulations you doubled your bet!!!"); }
break;



case 2: // Second world country calualtions//
amtwon= (200 / pbet) * 200 ;
amtlost= (pbet * 0.35);
totalwin[cnt2]= ( amtwon - amtlost);
avgwin = (play1 + play2 + totalwin[cnt2]) / 3;
ovwin = ovwin + totalwin[cnt2];

cnt2++ ;

system("cls");
printf("
Player Name : %s %s %s" ,fname,mname,lname );
printf("
Amount Won is : $JA %6.2f ",amtwon);
printf("
Amount Lost : $JA %1.f",amtlost);

// [b]Here is the display problem[/b]//
printf("
Total winnings : $JA %6.2f",totalwin[cnt2]);
printf("
Average Total Winnings : $JA %6.2f",avgwin);


if (totalwin[cnt2]>pbet+pbet)
{ printf("


Congratulations you doubled your bet!!!"); }
break;


case 3: // Third world country calculations//
amtwon= ( 100 % pbet ) *600 ;
amtlost= 500;
totalwin[cnt2]= ( amtwon - amtlost);
avgwin = (play1 + play2 + totalwin[cnt2]) / 3;
ovwin = ovwin + totalwin[cnt2];
cnt2 ++;

system("cls");
printf ("
Player Name : %s %s %s" ,fname,mname,lname );
printf("
Amount Won is : $JA %6.2f ",amtwon);
printf("
Amount Lost : $JA %1.f",amtlost);

// [b]Here is the display problem[/b]//
printf("
Total winnings : $JA %6.2f",totalwin[cnt2]);
printf("
Average Total Winnings : $JA %6.2f",avgwin);


// This message will come up if the user's bet is doubled//
if (totalwin[cnt2]>pbet+pbet)
{ printf("


Congratulations you doubled your bet!!!"); }
break;

// If the user does not input a value between 1 to 3 the program will terminate//
default : result =0;
printf("
Invalid Choice!!");
break;
} // ending of case //


// prompt asking user if the want to bet again//
printf("
do you want to restart ? y/n ");
scanf("%s",&c);
cnt = cnt + 1;
ovwin= ovwin + totalwin[cnt2];

} while (c == 'y' && cnt< 5 );// bonus player can only play 5 times//
// Ending of restart loop//



//[b]The number is correct here but is to 6 decimal places[/b]//
for (cnt2 = 0 ; cnt2 < cnt ; cnt2++)
{
printf("%f
",totalwin[cnt2]);
}
getch();
}

[/code]
Sign In or Register to comment.