<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Array display problem' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Array display problem' posted on the 'C and C++' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Wed, 19 Jun 2013 02:07:18 -0700</pubDate>
    <lastBuildDate>Wed, 19 Jun 2013 02:07:18 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Array display problem</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/430305/430305/array-display-problem/</link>
      <description>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. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
what am i doing wrong and how can i fix this ? &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;conio.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;

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",&amp;amp;choice);	

// This while loop ensures an error message will come up unless the right values are entered 	

while ( choice &amp;lt; 1 || choice &amp;gt;3)
	       { 
 	       printf(" Error please choose a number from the list above ");
           scanf("%d",&amp;amp;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",&amp;amp;pbet);
  
 
// This while loop ensure's that the user does not enter 0 or a negative value//
while ( pbet &amp;lt;= 0)
	       { 
 	       printf(" Error please enter a suitable bet amount ");
           scanf("%d",&amp;amp;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);
	 
          // &lt;strong&gt;Here is the display problem&lt;/strong&gt;//
           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]&amp;gt; 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);
          
          // &lt;strong&gt;Here is the display problem&lt;/strong&gt;//
           printf(" \nTotal winnings : $JA %6.2f",totalwin[cnt2]);
           printf(" \nAverage Total Winnings : $JA %6.2f",avgwin);
	        
		  
		   if (totalwin[cnt2]&amp;gt;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);
           
           // &lt;strong&gt;Here is the display problem&lt;/strong&gt;//
           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]&amp;gt;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",&amp;amp;c);
        cnt = cnt + 1;
        ovwin= ovwin + totalwin[cnt2];
  
  } while (c == 'y' &amp;amp;&amp;amp; cnt&amp;lt; 5 );// bonus player can only play 5 times//
 // Ending of restart loop//
 


//&lt;strong&gt;The number is correct here but is to 6 decimal places&lt;/strong&gt;//
 for (cnt2 = 0 ; cnt2 &amp;lt; cnt ; cnt2++)
 {
 printf("%f\n",totalwin[cnt2]);
}
 getch();
}

&lt;/pre&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/430305/430305/array-display-problem/</guid>
      <pubDate>Sun, 18 Nov 2012 09:07:49 -0700</pubDate>
      <category>C and C++</category>
    </item>
  </channel>
</rss>