Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Jeffrey-Kimani/a0ecf12d6ac686efb27bf98bb06421d0 to your computer and use it in GitHub Desktop.
Save Jeffrey-Kimani/a0ecf12d6ac686efb27bf98bb06421d0 to your computer and use it in GitHub Desktop.
Supermarket Assignment
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
<component name="CidrRootsConfiguration">
<sourceRoots />
<libraryRoots />
<excludeRoots />
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
<OptionsSetting value="true" id="Add" />
<OptionsSetting value="true" id="Remove" />
<OptionsSetting value="true" id="Checkout" />
<OptionsSetting value="true" id="Update" />
<OptionsSetting value="true" id="Status" />
<OptionsSetting value="true" id="Edit" />
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Supermarket_1.iml" filepath="$PROJECT_DIR$/.idea/Supermarket_1.iml" />
</modules>
</component>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<module type="CPP_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/main.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/CMakeLists.txt" isTestSource="false" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library name="Header Search Paths">
<CLASSES>
<root url="file://C:/Program Files (x86)/CodeBlocks/MinGW/lib/gcc/mingw32/4.8.1/include" />
<root url="file://C:/Program Files (x86)/CodeBlocks/MinGW/lib/gcc/mingw32/4.8.1/include-fixed" />
<root url="file://C:/Program Files (x86)/CodeBlocks/MinGW/include" />
</CLASSES>
<SOURCES>
<root url="file://C:/Program Files (x86)/CodeBlocks/MinGW/lib/gcc/mingw32/4.8.1/include" />
<root url="file://C:/Program Files (x86)/CodeBlocks/MinGW/lib/gcc/mingw32/4.8.1/include-fixed" />
<root url="file://C:/Program Files (x86)/CodeBlocks/MinGW/include" />
</SOURCES>
</library>
</orderEntry>
</component>
</module>
cmake_minimum_required(VERSION 3.5)
project(Supermarket_1)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(Supermarket_1 ${SOURCE_FILES})
#include <iostream>
#include <iomanip>
using namespace std;
using std::setw;
struct Item
{
string item;
int price;
};
void printItem(string,int);
int main()
{
int count,price,total=0,PaidAmmount;
string item;
cout<<"Enter the number of items to purchase: ";
cin >> count;
Item items [count];
for (int i = 0; i < count; ++i) {
cout<<"Enter the item name: ";
cin>>items[i].item;
cout<<"Enter the price: ";
cin>>items[i].price;
total+=items[i].price;
}
up:{
cout << "Ammount to pay: " << total<<endl;
cout << "Enter the ammount paid: ";
cin >> PaidAmmount;
if (PaidAmmount >= total) {
cout << "\n";
cout << setw(4) << "NAIVAS SUPERMARKET" << endl;
cout << "*******************************" << endl;
cout << "ITEMS" << setw(12) << "PRICE" << endl;
for (int i = 0; i < count; ++i) {
printItem(items[i].item, items[i].price);
}
cout << "\n";
cout << "Total" << setw(12) << total << endl;
cout << "Paid" << setw(12) << PaidAmmount << endl;
cout << "----------------------------------" << endl;
cout << "Change" << setw(12) << PaidAmmount-total << endl;
cout << "*******************************" << endl;
cout << "You were served by \n" << "Kevin Mutisya" << endl;
cout << "Thank you for shopping at Naivas" << endl;
}
else {
cout<<"You have paid an ammount less than the Total ammount payable"<<endl;
goto up;
}
}
return 0;
}
void printItem(string item,int price)
{
cout <<item<<setw(12)<<"Ksh."<<price <<endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment