Sunday, August 2, 2009

C progrmaming?

/*store the information in arrays*/


for (i=0; i %26lt; num_deals; i++)


{





printf("enter pizza name please do not use spaces between names: \n");


scanf("%s",pizzaDeals[i].PizzaCompanyNam...











printf("enter size: \n");


scanf("%f", %26amp;pizzaDeals[i].pizzaSize);











printf("enter price: \n");


scanf("%f", %26amp;pizzaDeals[i].price);





count++;


}





/*decipher which pizza is the cheapest*/


/*use for loop*/


for( i = 0; i %26lt; count; i++)


{


if( pizzaDeals[i].price/pizzaDeals[i].pizzaS... %26lt; bestPrice)


{


bestPrice = pizzaDeals[i].price/pizzaDeals[i].pizzaS...


bestIndex = i;


}


}


how does the above code spit out the smallest value

C progrmaming?
The loop that is checking for the cheapest pizza is acting in a fashion like a 'bubble sort', where the highest (or smallest in this case) will 'bubble' to the top. In this case, the best price is evaluated on price/slice over the complete set of pizza parlors. The first pizza parlot (i == 0) will have the inital low price, but as you work through the arry, other pizza places may be cheaper. They in turn will become the most economical pizza. Of course, just because they are cheap doesnt mean they are any good... ;)

parts of a flower

No comments:

Post a Comment