Skip to content

Instantly share code, notes, and snippets.

@andraantariksa
Created February 12, 2019 07:43
Show Gist options
  • Save andraantariksa/63d6206021bcbc60110940a732c2a211 to your computer and use it in GitHub Desktop.
Save andraantariksa/63d6206021bcbc60110940a732c2a211 to your computer and use it in GitHub Desktop.
Assignment Structured Programming 2
#include <iostream>
int main(int argc, char const *argv[]){
short command;
unsigned int itemstotal = 5;
float total[2] = {0};
struct Items{
std::string name;
unsigned int price;
unsigned char type;
unsigned short amount = 0;
};
//type 1 for food
//type 2 for other things
Items items[itemstotal];
// ################################
items[0].name = "Roti";
items[0].price = 15000;
items[0].type = 1;
items[1].name = "Chiki";
items[1].price = 3000;
items[1].type = 1;
items[2].name = "Keik";
items[2].price = 7000;
items[2].type = 1;
items[3].name = "Baterai";
items[3].price = 12000;
items[3].type = 2;
items[4].name = "Pasta Gigi";
items[4].price = 5000;
items[4].type = 2;
// ################################
while(1){
std::cout<<"=============================================="<<std::endl;
std::cout<<"LITE MART CASHIER SYSTEM"<<std::endl;
std::cout<<"======================FOOD===================="<<std::endl;
total[0] = 0;
for(unsigned int i = 0; i < itemstotal; i++){
if(items[i].type == 1){
std::cout<<i+1<<" | "<<items[i].name<<"\t\t"<<items[i].price<<"\t| "<<items[i].amount<<std::endl;
total[0] += items[i].amount*items[i].price;
}
}
std::cout<<"Food total price = "<<total[0]<<std::endl;
std::cout<<"Tax (12%) = "<<(total[0]*0.12)<<std::endl;
std::cout<<"Food total price + tax = "<<(total[0]+total[0]*0.12)<<std::endl;
total[0] = (total[0]+total[0]*0.12);
std::cout<<"======================OTHER==================="<<std::endl;
total[1] = 0;
for(unsigned int i = 0; i < itemstotal; i++){
if(items[i].type == 2){
std::cout<<i+1<<" | "<<items[i].name<<"\t\t"<<items[i].price<<"\t| "<<items[i].amount<<std::endl;
total[1] += items[i].amount*items[i].price;
}
}
std::cout<<"Other total price = "<<total[1]<<std::endl;
std::cout<<"Tax (25%) = "<<(total[1]*0.25)<<std::endl;
std::cout<<"Other total price + tax = "<<(total[1]+total[1]*0.25)<<std::endl;
total[1] = (total[1]+total[1]*0.25);
std::cout<<"=============================================="<<std::endl;
std::cout<<"Total (incl. tax)"<<std::endl;
std::cout<<"= "<<total[0]<<" (food) + "<<total[1]<<" (other)"<<std::endl;
std::cout<<"= "<<total[0]+total[1]<<std::endl;
std::cout<<"=============================================="<<std::endl;
std::cout<<"> ";
std::cin>>command;
if(command != 0){
std::cout<<"\n\n\n\n\n\n\n";
}else{
return 0;
}
if(command >= 1 && command <= itemstotal){
items[command-1].amount++;
}else if(command <= -1 && command >= itemstotal){
if(items[-(command)-1].amount > 0){
items[-(command)-1].amount--;
}else{
std::cout<<"Error"<<std::endl;
}
}else{
std::cout<<"Error"<<std::endl;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment