# Thread: I'm confused on how to make my program show two different answers depending on what n

1. ## I'm confused on how to make my program show two different answers depending on what n

Hello,
I have two questions with the code i've written. (Hopefully this will make sense as well as the code i've written.)This is my first experience with C programming and recently received a programming problem. "A grocery store is selling oranges for 9 cents a piece or one dollar per dozen." In the code i've written, the program multiplies the 9 * any number I input. My problem is I don't know how to make the program show that when i input 12 oranges, it will come to one dollar. I get 1.08 and i've tried different methods, but i'm very stumped on how to make every dozen 12, 24, 36, etc. become \$1,2,3 instead of \$1.08, 2.16, etc.
Also how can i add a decimal to the amount in the correct slots for dollars and cents like
\$4.15 instead of \$415 or \$.36 instead of \$36. Do i use a floater for that? I would really appreciate anyone giving me some pointers on this problem. Thank you....

void function (int single_orange, int total_oranges);

int main(void)
{
int single_orange, total_oranges;

single_orange = 9;

printf(" The price of a single orange is 9 cents \n");

printf(" The price of a dozen oranges is 1 dollar \n");

printf( "Enter the number of oranges you would like to purchase and press enter: ");
scanf( "%d", &total_oranges );

printf( "%d * %d \n", single_orange, total_oranges);

printf("Your total comes to: \$%d \n", single_orange * total_oranges);

return 0;
} 2. Add another variable to track the price. Now then, while total_oranges is greater than 12, subtract 12 from total_oranges and add a dollar to price. After the while statement, total_oranges will be some number from zero to eleven. Multiply total_oranges with single_orange and add the result to price.

Hope that helps, Popular pages Recent additions 