In: Computer Science
Create a CodeBlocks project with a main.cpp file. Submit the main.cpp file in Canvas. C++ Language
A Game store sells many types of gaming consoles. The console brands are Xbox, Nintendo, PlayStation.
A console can have either 16 or 8 gigabytes of memory.
Use can choose the shipping method as either Regular (Cost it $5) or Expedite (Cost is $10)
The price list is given as follows:
Memory size/Brand Xbox Nintendo PlayStation
16 gigabytes 499.99 469.99 409.99
8 gigabytes 419.99 379.99 339.99
Determine the price of a given console dependent on the user inputs. The sales tax is 9.75% for each console.
Validation:
For the brand name, use input can be X for Xbox, N for Nintendo or P for PlayStation in upper letter case only.
For memory size user input can only be 8 or 16.
The input quantity should be 0 or positive, but must not exceed 20.
The shipping method can only be R or E.
If any user input is not correct, display an error message and skip all calculation.
Print the brand name and the quantity in the price calculation, for example with 16 gigabytes:
The item price for (2 x Xbox) is $999.98
All currency amounts should be displayed with 2 digits in decimal fraction.
There is No need to use a loop for repetition.
Here are several separate program sample runs.
Welcome to the Game store.
Enter the brand name of the game console (X for Xbox, N for Nintendo, P for PlayStation): X
Enter the memory size of the game console (8 or 16 gigabytes): 16
Enter quantity to buy: 2
The item price for (2 x Xbox) is $999.98
The sale tax is $ 97.50
Enter shipping method (R for Regular, E for Expedite): R
Shipping cost is $5.00
The total bill is $1102.48
----------------------
#include <iostream>
using namespace std;
double round(double var)
{
double value = (int)(var * 100 + .5);
return (double)value / 100;
}
int main()
{
char console,shipping,index=-1;
int GB,quantity;
double price,tax,shipcost;
double eightGB[] = {419.99, 379.99, 339.99};
double sixteenGB[] = {499.99, 469.99, 409.99};
cout<<"Enter the brand name of the game console (X for Xbox, N for Nintendo, P for PlayStation):";
cin>>console;
switch(console){
case 'X':
index = 0;
break;
case 'N':
index = 1;
break;
case 'P':
index = 2;
break;
default:
cout<<"Please enter valid input";
exit(0);
}
cout<<"Enter the memory size of the game console (8 or 16 gigabytes):";
cin>>GB;
cout<<"Enter quantity to buy:";
cin>>quantity;
if(GB!=8 || GB!=16){
cout<<"Please enter valid input";
exit(0);
}
if(quantity<0 && quantity>20){
cout<<"Please enter valid input";
exit(0);
}
if(GB==8){
price = eightGB[index]*quantity;
}else if(GB==16){
price = sixteenGB[index]*quantity;
}
cout<<"The item price for ("<<quantity<<" x Xbox) is $"<<price;
tax = round(price*0.0975);
cout<<"\nThe sale tax is $"<<tax;
cout<<"\nEnter shipping method (R for Regular, E for Expedite):";
cin>>shipping;
if(shipping=='R'){
cout<<"Shipping cost is $5.00";
shipcost = 5.00;
}else if(shipping=='E'){
cout<<"Shipping cost is $10.00";
shipcost = 10.00;
}
cout<<"\nThe total bill is $"<<(price+tax+shipcost);
return 0;
}