Untitled
unknown
plain_text
10 months ago
1.4 kB
3
Indexable
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
const int a = 5;
string items[a] = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
double prices[a] = { 10.5, 11.5, 12.5, 13.5, 14.5 };
int quantities[a] = { 0 };
double totalbill = 0;
cout <<"Prices per Item: \n";
cout << "Item 1" << setw(16) << 10.5 << endl;
cout << "Item 2" << setw(16) << 11.5 << endl;
cout << "Item 3" << setw(16) << 12.5 << endl;
cout << "Item 4" << setw(16) << 13.5 << endl;
cout << "Item 5" << setw(16) << 14.5 << endl;
for (int i = 0; i < a; i++)
{
cout << "Enter quantity of " << items[i] << " (in kg): ";
cin >> quantities[i];
}
cout << "\nYour Bill:\n";
cout << setw(12) << "Item"
<< setw(10) << "Price"
<< setw(10) << "Qty"
<< setw(12) << "Total\n";
for (int i = 0; i < a; i++)
{
double itemtotal = prices[i] * quantities[i];
totalbill += itemtotal;
cout << setw(12) << items[i]
<< setw(10) << fixed << setprecision(2) << prices[i]
<< setw(10) << quantities[i]
<< setw(12) << itemtotal << "\n";
}
cout << "\n" << setw(34) << "Grand Total: " << fixed << setprecision(2) << totalbill << " INR\n";
return 0;
}
Editor is loading...
Leave a Comment