Quantcast
Viewing all articles
Browse latest Browse all 2703

Array display problem

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 ?

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>

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("\n Enter 1 for first world country !\n");
 printf(" Enter 2 for second world country !\n");
 printf(" Enter 3 for thrid world country !\n");
 printf("\n 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("\n\nYou are from a first world country"); 
           }  
else
    {    
	       if (choice==2)
           { 
  	       printf("\n\nYou are from a second world country"); 
           }
else 
           if (choice==3)
	       { 
           printf("\n\nYou are from a thrid world country"); 
           }   
     
	 else 
	       printf(" "); 
    }
// User is asked to imput their information//
           printf(" \nEnter your first name :");
	       scanf("%s",fname);
	   
	       printf(" \nEnter your middle name: ");
	       scanf("%s",mname);
	   
	       printf(" \nEnter 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( "\nEnter 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("\nPlayer Name : %s %s %s" ,fname,mname,lname ); 
	 printf(" \nAmount Won is : $JA %6.2f ",amtwon);
        printf(" \nAmount Lost  : $JA %1.f",amtlost);
          // Here is the display problem//
           printf(" \nTotal winnings : $JA %6.2f",totalwin[cnt2]);
         printf(" \nAverage Total Winnings : $JA %6.2f",avgwin);
// This message will come up if the user's bet is doubled//
			if (totalwin[cnt2]> pbet+pbet)
          { printf("\n\n\nCongratulations 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("\nPlayer Name : %s %s %s" ,fname,mname,lname ); 	  
	   printf(" \nAmount Won is : $JA %6.2f ",amtwon);
           printf(" \nAmount Lost  : $JA %1.f",amtlost);
          // Here is the display problem//
           printf(" \nTotal winnings : $JA %6.2f",totalwin[cnt2]);
           printf(" \nAverage Total Winnings : $JA %6.2f",avgwin);
		   if (totalwin[cnt2]>pbet+pbet)
        {  printf("\n\n\nCongratulations 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   ("\nPlayer Name : %s %s %s" ,fname,mname,lname ); 
	   printf(" \nAmount Won is : $JA %6.2f ",amtwon);
           printf(" \nAmount Lost  : $JA %1.f",amtlost);
           // Here is the display problem//
           printf(" \nTotal winnings : $JA %6.2f",totalwin[cnt2]);
           printf(" \nAverage Total Winnings : $JA %6.2f",avgwin);
		  // This message will come up if the user's bet is doubled//
	       if (totalwin[cnt2]>pbet+pbet)
     {     printf("\n\n\nCongratulations 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("\n Invalid Choice!!");
           break;
     }	// ending of case //
	    // prompt asking user if the want to bet again//
		printf("\ndo 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//


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

Viewing all articles
Browse latest Browse all 2703

Trending Articles