back again with another question in C. i'm having some issues with my switch statements. my program is compiling and running its even storing the correct values in the correct variables and running through the switch statements as it should EXCEPT when it comes to print out specific output. please keep in mind i am trying to learn and my knowledge is very basic. i appreciate all your help in this fascinating community and i ask that your responses if any would help me learn more!
without further ado here comes a wall of coded text!
// Point of sale software that lists a set of packages with a subset of possible upgrades for each
/*This C program was written with a zoom value of 100 and with the use of wordwrap
the native resolution of the screen is set to 1920x1080
for easiest veiwing make sure wordwrap is up*/
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
int package = 0, memory = 0, hd = 0, monitor = 0, gpu = 0, another = 0;
float price = 0, memprice = 0, hdprice = 0, monprice = 0, gpuprice = 0, subtotal = 0, hst = 0, total = 0;
printf("Welcome to the IPC Company's Computer System Calculator\nthe package desired\n(1: basic, 2 : professional, 3 : game system) : ");
scanf("%d", &package);
do // the condition to break the loop is to have the user input 0 into the variable another
{
if (package == 1) //selects the basic package and stores user selections of upgrades
{
price = 599;
printf("Enter additional memory required\n(0: 4 GB included, 1 : 8 GB, 2 : 12 GB) : ");
scanf("%d", &memory);
printf("Enter monitor required\n(0: 21 inch LED included, 1 : 27 inch LED) : ");
scanf("%d", &monitor);
printf("Enter Hard Drive drive required\n(0: 512 GB included, 1 : 128 GB SSD) : ");
scanf("%d", &hd);
printf("\n\n========================================\n");
printf("Basic Package 599.00\n");
}
else if (package == 2)// selects the professional package and stores user selections of upgrades
{
price = 899;
printf("Enter additional memory required\n(0: 8 GB included, 1 : 16 GB) : ");
scanf("%d", &memory);
memory += 3;
printf("Enter monitor required\n(0: 27 inch LED included, 1 : 32 inch LED) : ");
scanf("%d", &monitor);
monitor += 2;
printf("Enter Hard Drive drive required\n(0: 1 TB included, 1 : 256 GB SSD, 2 : 512 GB SSD) : ");
scanf("%d", &hd);
hd += 2;
printf("Enter Video Card required\n(0: IGP included, 1 : 2 GB Discrete) : ");
scanf("%d", &gpu);
gpu += 1;
printf("\n\n========================================\n");
printf("Professional Package 899.00\n");
}
else
{
price = 1499; //selects the gaming package and stores user selections for upgrades
printf("Enter additional memory required\n(0: 16 GB included, 1 : 32 GB) : ");
scanf("%d", &memory);
memory += 5;
printf("Enter monitor required\n(0: 32 inch LED included, 1 : 28 inch 4K HD) : ");
scanf("%d", &monitor);
monitor += 4;
printf("Enter Hard Drive drive required\n(0: 256 GB SSD included, 1 : 512 GB SSD, 2 : 1 TB SSD) : ");
scanf("%d", &hd);
hd += 5;
printf("Enter Video Card required\n(0: 2 GB Discrete included, 1 : 4 GB Discrete) : ");
scanf("%d", &gpu);
gpu += 3;
printf("\n\n========================================\n");
printf("Gaming Package 1499.00\n");
//values for each variable is upcast by an appropriate amount to keep input either 0 1 2 while storing them as 0 to 8+ to allow
//the use of four switches as apposed to a switch for each individual package/component combination
//partial credit to professor joseph hughes for shedding light on this methodology
}
switch (memory)//4 switch catagories based on memory hd gpu and monitor each containing a pre defined price
{
case 0:
memprice = 0;
printf("4 GB Memory: 0.00\n");
break;
case 1:
memprice = 99;
printf("8 GB Memory: 99.00\n");
break;
case 2:
memprice = 189;
printf("12 GB Memory: 189.00\n");
break;
case 3:
memprice = 0;
printf("8 GB Memory: 0.00\n");
break;
case 4:
memprice = 189;
printf("16 GB Memory: 189.00\n");
break;
case 5:
memprice = 0;
printf("16 GB Memory: 0.00\n");
break;
case 6:
memprice = 389;
printf("32 GB Memory: 389.00\n");
break;
}
switch (monitor)
{
case 0:
monprice = 0;
printf("21 inch LED Monitor 0.00\n");
break;
case 1:
monprice = 199;
printf("27 inch LED Monitor 199.00\n");
break;
case 2:
monprice = 0;
printf("27 inch LED Monitor 0.00\n");
break;
case 3:
monprice = 199;
printf("32 inch LED Monitor 199.00\n");
break;
case 4:
monprice = 0;
printf("32 inch LED Monitor 0.00\n");
break;
case 5:
monprice = 299;
printf("28 inch 4K LED Monitor 299.99\n");
break;
}
switch (hd)
{
case 0:
hdprice = 0; printf("512 GB Hard Drive 0.00\n");
break;
case 1:
hdprice = 119;
printf("128 GB SSD 119.00\n");
break;
case 2:
hdprice = 0;
printf("1 TB Hard Drive 0.00\n");
break;
case 3:
hdprice = 189;
printf("256 GB SSD 189.00\n");
break;
case 4:
hdprice = 399;
printf("512 GB SSD 399.99\n");
break;
case 5:
hdprice = 0;
printf("256 GB 0.00\n");
break;
case 6:
hdprice = 299;
printf("512 GB SSD 299.00\n");
break;
case 7:
hdprice = 599;
printf("1TB SSD 599.00\n");
break;
}
switch (gpu)
{
case 0:
gpuprice = 0;
break;
case 1:
gpuprice = 0;
printf("IGP Video 0.00\n");
break;
case 2:
gpuprice = 209;
printf("Discrete 2GB Video 209.00\n");
break;
case 3:
gpuprice = 0;
printf("Discrete 2GB Video 0.00\n");
break;
case 4:
gpuprice = 399;
printf("Discrete 4GB Video 399.00\n");
break;
}
subtotal = price + memprice + monprice + gpuprice + hdprice;
hst = subtotal*.13;
total = subtotal + subtotal*.13;
printf("========================================\n");
printf("Sub Total: %.2f\n", subtotal);
printf("HST: %.2f\n", hst);
printf("========================================\n");
printf("Total: %.2f\n", total);
printf("Do you wish to choose another computer package? (1: YES or 0: NO): ");
scanf("%d", &another);
// note most prices are registerd as string literals and not variable calls with the exclusion of subtotal hst and total
} while (another == 1);
return 0;
}