Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* dycesM */
- #include <iostream>
- #include <string>
- #include <string.h>
- using namespace std;
- int money = 5000; // Global Variable
- struct database
- {
- string songName;
- int songPrice;
- int songNumber;
- int songID;
- }userStorage[30], storeStorage[30];
- struct transaction
- {
- string songName;
- int songPrice;
- }transactionStorage[30];
- void userStorageDisplay()
- {
- for (int i = 0; i <= 30; i++)
- {
- if (userStorage[i].songID != NULL)
- {
- cout << "\n" << i << ". " << userStorage[i].songName << "\n" << endl;
- }
- }
- }
- void storeStorageDisplay()
- {
- for (int i = 0; i <= 30; i++)
- {
- if (storeStorage[i].songID != NULL)
- {
- cout << "\n" << i << ". " << storeStorage[i].songName << endl;
- cout << "\t" << "Price: $" << storeStorage[i].songPrice << "\n" << endl;
- }
- }
- }
- void transactionStorageDisplay()
- {
- for (int i = 0; i < 30; i++)
- {
- if (transactionStorage[i].songPrice != NULL)
- {
- cout << "\n" << transactionStorage[i].songName << " $:" << transactionStorage[i].songPrice << "\n" << endl;
- }
- }
- }
- int checkDuplicate(int songStorageValue)
- {
- for (int j = 0; j <= 30; j++)
- {
- if (userStorage[j].songID == storeStorage[songStorageValue].songID)
- {
- return 0;
- }
- }
- return 1;
- }
- int checkBankDetails(int songNumber)
- {
- if (storeStorage[songNumber].songPrice > money)
- {
- return 1;
- }
- }
- void purchase(int songNumber)
- {
- int verification;
- int &moneyBalance = money;
- cout << "\nAre you sure you wish to purchase: " << storeStorage[songNumber].songName << " for a price of: " << storeStorage[songNumber].songPrice << " ?" << endl;
- cout << "Press 1 to confirm or 2 to exit." << endl;
- cin >> verification;
- if (verification == 1)
- {
- if (checkBankDetails(songNumber) != 1)
- {
- if (checkDuplicate(songNumber) == 1)
- {
- for (int i = 0; i <= 30; i++)
- {
- if (userStorage[i].songID == NULL)
- {
- userStorage[i].songName = storeStorage[songNumber].songName;
- userStorage[i].songNumber = i;
- userStorage[i].songPrice = storeStorage[songNumber].songPrice;
- userStorage[i].songID = storeStorage[songNumber].songID;
- for (int a = 0; a <= 30; a++)
- {
- if (transactionStorage[a].songPrice == NULL)
- {
- transactionStorage[a].songName = storeStorage[songNumber].songName;
- transactionStorage[a].songPrice = storeStorage[songNumber].songPrice;
- money = money - transactionStorage[a].songPrice;
- cout << "\nRemaining Value: $" << money << "\n";
- a = 30; // To end the loop.
- }
- }
- cout << "\n" << storeStorage[songNumber].songName << " has been added to your library at position number: " << i << "\n" << endl;
- i = 30; // To end the loop.
- }
- }
- }
- else if (checkDuplicate(songNumber) == 0)
- {
- cout << "\nYou already own this song. Purchase Cancelled." << endl;
- }
- }
- else if (checkBankDetails(songNumber) == 1)
- {
- cout << "\nInsufficient funds. Purchase cancelled." << endl;
- }
- }
- else if (verification != 1)
- {
- cout << "Transaction Aborted.";
- }
- }
- void main()
- {
- char rerun;
- //Store Song's added for demonstration purposes.
- storeStorage[0].songName = "Daughter - Youth";
- storeStorage[0].songPrice = 25;
- storeStorage[0].songID = 2000;
- storeStorage[1].songName = "Archive - Bullets";
- storeStorage[1].songPrice = 25;
- storeStorage[1].songID = 2001;
- storeStorage[2].songName = "Swedish House Mafia - Don't you worry child";
- storeStorage[2].songPrice = 25;
- storeStorage[2].songID = 2002;
- storeStorage[3].songName = "Roykossop - Running to the sea";
- storeStorage[3].songPrice = 25;
- storeStorage[3].songID = 2003;
- storeStorage[4].songName = "French Teen Idol - Shouting can have different meanings";
- storeStorage[4].songPrice = 25;
- storeStorage[4].songID = 2004;
- storeStorage[5].songName = "From Outer Space - THe Future";
- storeStorage[5].songPrice = 25;
- storeStorage[5].songID = 2005;
- storeStorage[6].songName = "Second Suspense - Immortal";
- storeStorage[6].songPrice = 25;
- storeStorage[6].songID = 2006;
- storeStorage[7].songName = "John Legend - All of me";
- storeStorage[7].songPrice = 25;
- storeStorage[7].songID = 2007;
- storeStorage[8].songName = "One Republic - Counting Stars";
- storeStorage[8].songPrice = 25;
- storeStorage[8].songID = 2008;
- storeStorage[9].songName = "Max Richter - The nature of daylight";
- storeStorage[9].songPrice = 25;
- storeStorage[9].songID = 2009;
- storeStorage[10].songName = "The Glitch Mob - Forture Days";
- storeStorage[10].songPrice = 25;
- storeStorage[10].songID = 2010;
- storeStorage[11].songName = "French Teen Idol - (un)Told Prejudice";
- storeStorage[11].songPrice = 25;
- storeStorage[11].songID = 2011;
- storeStorage[12].songName = "Angus and Julia Stone - All of me";
- storeStorage[12].songPrice = 25;
- storeStorage[12].songID = 2012;
- storeStorage[13].songName = "Temple - Final Years";
- storeStorage[13].songPrice = 25;
- storeStorage[13].songID = 2013;
- storeStorage[14].songName = "Metric - Help I'm Alive";
- storeStorage[14].songPrice = 25;
- storeStorage[14].songID = 2014;
- storeStorage[15].songName = "Of Monsters and Men - Little Talk";
- storeStorage[15].songPrice = 25;
- storeStorage[15].songID = 2015;
- storeStorage[16].songName = "Yuna - Lullabies";
- storeStorage[16].songPrice = 25;
- storeStorage[16].songID = 2016;
- storeStorage[17].songName = "Krewella - Rise & Fall";
- storeStorage[17].songPrice = 25;
- storeStorage[17].songID = 2017;
- storeStorage[18].songName = "Gemini - Blue";
- storeStorage[18].songPrice = 25;
- storeStorage[18].songID = 2018;
- storeStorage[19].songName = "Apex - Inner Space";
- storeStorage[19].songPrice = 25;
- storeStorage[19].songID = 2019;
- storeStorage[20].songName = "Daft Punk - Get Lucky";
- storeStorage[20].songPrice = 25;
- storeStorage[20].songID = 2020;
- storeStorage[21].songName = "Daft Punk - Something about us";
- storeStorage[21].songPrice = 25;
- storeStorage[21].songID = 2021;
- storeStorage[22].songName = "Ramesses B - I need you";
- storeStorage[22].songPrice = 25;
- storeStorage[22].songID = 2022;
- storeStorage[23].songName = "Phaeleh - In the twilight";
- storeStorage[23].songPrice = 25;
- storeStorage[23].songID = 2023;
- storeStorage[24].songName = "Tom Day - Going Home";
- storeStorage[24].songPrice = 25;
- storeStorage[24].songID = 2024;
- storeStorage[25].songName = "Hans Zimmer - Time";
- storeStorage[25].songPrice = 25;
- storeStorage[25].songID = 2025;
- storeStorage[26].songName = "Awolnation - Sail";
- storeStorage[26].songPrice = 25;
- storeStorage[26].songID = 2026;
- storeStorage[27].songName = "Sia - Breathe Me";
- storeStorage[27].songPrice = 25;
- storeStorage[27].songID = 2027;
- storeStorage[28].songName = "Lemaitre - Keep Close";
- storeStorage[28].songPrice = 25;
- storeStorage[28].songID = 2028;
- storeStorage[29].songName = "Justin Beiber - Dead";
- storeStorage[29].songPrice = 25;
- storeStorage[29].songID = 2029;
- do
- {
- int userOperationChoice;
- int userPurchaseQuery;
- cout << "Hello and Welcome to the Dyces Song Library. \n\nPlease select one of the operations below. \n\n 1 - View your own library \n\n 2 - View the Store Library \n\n 3 - View your transactions. \n\n 4 - Check Bank Details \n\n Selection:";
- cin >> userOperationChoice;
- switch (userOperationChoice)
- {
- case(1) :
- {
- goto userLibrary;
- break;
- }
- case(2) :
- {
- goto storeLibrary;
- break;
- }
- case(3) :
- {
- goto transactionLibrary;
- break;
- }
- case(4) :
- {
- goto bankDetails;
- break;
- }
- }
- userLibrary:
- system("CLS");
- cout << "\nThe current songs in your library are: \n\n";
- userStorageDisplay();
- goto programEnd;
- storeLibrary:
- system("CLS");
- cout << "\nThe Store's library is: \n";
- storeStorageDisplay();
- cout << "\nPlease enter the song you wish to purchase. \n";
- cin >> userPurchaseQuery;
- purchase(userPurchaseQuery);
- goto programEnd;
- transactionLibrary:
- system("CLS");
- cout << "Your transactions are: \n";
- transactionStorageDisplay();
- goto programEnd;
- bankDetails:
- char viewTransactionHistory;
- system("CLS");
- cout << "You have: $" << money << " left in your bank account." << endl;
- cout << "\nWould you like to check your transaction history? Y/N" << endl;
- cin >> viewTransactionHistory;
- if (viewTransactionHistory == 'y' || viewTransactionHistory == 'Y')
- {
- goto transactionLibrary;
- }
- goto programEnd;
- programEnd:
- cout << "\nWould you like to go back to the main menu? Y/N" << endl ;
- cin >> rerun;
- system("CLS");
- } while (rerun == 'y' || rerun == 'Y');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement