I wrote this simple program in C:
/*
* Exercise 2-3. *
* You’re selling a product that’s available in two versions: *
* type 1 is a standard version priced at $3.50, and *
* type 2 is a deluxe version priced at $5.50. *
* Write a program using only what you’ve learned up to now *
* that prompts for the user to enter the product type and a quantity, *
* and then calculates and outputs the price for the quantity entered. */
#include <stdio.h>
int main(void)
{
short int q=0; /* quantity */
short int x=0; /* selection switch */
//prompt for version and quantity
printf("\nPlease, give the type 1:normal, 2:deluxe: ");
scanf("%d",&x);
printf("\nPlease, give the quantity: ");
scanf("%d",&q);
//calculations - printout
printf("\nThe Total price is: %0.2f\n", (x*2+1.5)*q);
return 0;
}
when I exchange the lines:
short int q=0; /* quantity */
short int x=0; /* selection switch */
each-other (declaring first the x and after the q) the result is wrong.
I use the Code::Blocks 8.02 built Feb27 2008 wx2.8.7(windows version)