Question: This coding is make by CHU KUN QUAN in INTI University Nilai) I declare this to avoid plagiarism for this feb 25 2023 assignment to
This coding is make by CHU KUN QUAN in INTI University Nilai) I declare this to avoid plagiarism for this feb 25 2023 assignment to lecture Ms Chong if you found my article here.)
Need help, to make it allow to user enter exact amount and can change money to user after user entered greater amount.
on the receipt function if (paymentAmount >= roundedTotal - 0.001 && paymentAmount <= roundedTotal + 0.001) then it only allow user enter exact amount, if greater than exact amount it will not change, it will show payment unsuccessful.
if (paymentAmount >= roundedTotal) It will change but it can't enter exact amount For example 0.38 onglai, user enter payment amount 0.38, it will show unsufficient payment. (Give me your full coding after updated version, tq)
Can access the full code below ( chegg only allow 16000 character)
https://onlinegdb.com/dD-zChipQ
#include
using namespace std;
const int NUM_FRUITS = 3; const int NUM_SUN_DRYS = 3; const int NUM_DAIRY = 3; const int MAX_LOGIN = 3; const float roud = 0.005;
struct Item { string name; float price; int quantity; };
void clearCart(Item items[], int numItems, double &total, int &totalQuantity) { for (int i = 0; i < numItems; i++) { items[i].quantity = 0; } total = 0; totalQuantity = 0; }
void addtoCart(Item items[], int numItems, double &total, int &totalQuantity)
{ int selection, quantity; cout << "Enter the number of the item you want to add to your cart: "; cin >> selection; cout << "Enter the quantity: "; cin >> quantity; if (selection > 0 && selection <= numItems) { items[selection - 1].quantity += quantity; total += items[selection - 1].price * quantity; totalQuantity += quantity; cout << "Added " << quantity << " " << items[selection - 1].name << " to cart." << endl; } else { cout << "Invalid Selection. Please try again." << endl; } }
void displayCategory(string category, Item items[], int numitems) { cout << category << endl; for (int i = 0; i < numitems; i++) { int quantity = items[i].quantity; int originalquantity = numitems - quantity; if (quantity > 0) { cout << i + 1 << ". " << items[i].name << ", quantity in cart: " << quantity << " - RM" << items[i].price << endl; } else { cout << i + 1 << ". " << items[i].name << " - RM" << items[i].price << endl; } } }
bool login() { string username, password; cout << "Welcome to George's supermarket!!Murah Murah!! Your username is admin and password is password, Thank you"; cout << " Enter your username: "; cin >> username; cout << "Enter your password: "; cin >> password; return username == "admin" && password == "password"; }
void receipt(double total, string paymentMethod, string creditcardInformation, string email, Item fruits[], int NUM_FRUITS, Item dried_goods[], int NUM_SUN_DRYS, Item dairy[], int NUM_DAIRY, int totalQuantity) { double roundedTotal = round((total + roud) * 100) / 100.0; cout << "Your receipt " << endl; cout << "Your payment method: " << paymentMethod << endl; cout << "Your credit card information: " << creditcardInformation << endl; cout << "Items:" << endl;
for (int i = 0; i < NUM_FRUITS; i++) { if (fruits[i].quantity > 0) { cout << fruits[i].name << " (quantity: " << fruits[i].quantity << ") - RM" << fruits[i].price * fruits[i].quantity << endl; } } for (int i = 0; i < NUM_SUN_DRYS; i++) { if (dried_goods[i].quantity > 0) { cout << dried_goods[i].name << " (quantity: " << dried_goods[i].quantity << ") - RM" << dried_goods[i].price * dried_goods[i].quantity << endl; } } for (int i = 0; i < NUM_DAIRY; i++) { if (dairy[i].quantity > 0) { cout << dairy[i].name << " (quantity: " << dairy[i].quantity << ") - RM" << dairy[i].price * dairy[i].quantity << endl; } } float paymentAmount; cout << "Total Cost: " << roundedTotal << endl; cout << "Enter PaymentAmount: "; cin >> paymentAmount; if (paymentAmount >= roundedTotal - 0.001 && paymentAmount <= roundedTotal + 0.001) { double change = paymentAmount - roundedTotal; cout << fixed << setprecision(2) << "Thank you! Payment successful. Your change is " << change << endl;
for (int i = 0; i < NUM_FRUITS; i++) { fruits[i].quantity = 0; } for (int i = 0; i < NUM_SUN_DRYS; i++) { dried_goods[i].quantity = 0; } for (int i = 0; i < NUM_DAIRY; i++) { dairy[i].quantity = 0; } total = 0.0; totalQuantity = 0; }else{ cout << "Payment unsuccessful. Pay less than total amount, cart will be cleared" << endl; clearCart(fruits, NUM_FRUITS, total, totalQuantity); clearCart(dried_goods, NUM_SUN_DRYS, total, totalQuantity); clearCart(dairy, NUM_DAIRY, total, totalQuantity);
} }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
