Hello, I’m new to coding and I’m currently taking my first class which is C++. On my first assignment, I was given the instructions:
Create a C++ Console application with an output similar to a store receipt with five items. Declare five string variables to hold the names of the items and five numeric variables to hold the prices of the items. Create a constant variable to hold the tax percentage of 9.25% (0.0925). Add codes to calculate the subtotal, tax amount, and total cost. Tax amount is calculated by multiplying subtotal by tax percentage.
Choose your own names for the items. Use the following prices: $12.95, $34.13, $9.32, $15.18, and $32.99.
Do not use meaningless variable names like item1, item2, and price1. Use meaningful names for your variables, like shirt and shoes."
The professor gave me these comments:
“shirtcost? Backpackcost? Must use camel casing. Please refer to the handout variable naming rules and conventions. Five string variables have been created, but they have never been used! total = subtotal + TAX_PERCENTAGE? The tax amount must be added to subtotal, not the percentage. That is why you have calculated the tax.”
I don’t understand what “must use camel casing” means, I don’t understand how the string variables were not used, and what is wrong with my total calculation. My professor just tells me to go through the book but that’s how I came up with the code I submitted can someone please explain what I did wrong?
// A Sale Receipt
#include <iostream>
using namespace std;
#include <string>
int main()
{
// String variables
string shirt = "Shirt";
string backpack = "Backpack";
string pants = "Pants";
string beanie = "Beanie";
string bag = "Bag";
// numeric variables
double shirtcost = 12.95;
double backpackcost = 34.13;
double pantscost = 9.32;
double beaniecost = 15.18;
double bagcost = 32.99;
// Tax
const double TAX_PERCENTAGE = 0.0925;
// Calculate subtotal
double subtotal = shirtcost + backpackcost + pantscost + beaniecost + bagcost;
// Calculate tax amount
double tax = subtotal * TAX_PERCENTAGE;
// Calculate total the total is subtotal + the tax, use double because decmials
double total = subtotal + TAX_PERCENTAGE;
//Display cost, items, and totals
cout << "Item Price" << endl;
cout << "Shirt $" << shirtcost << endl;
cout << "Backpack $" << backpackcost << endl;
cout << "Pants $" << pantscost << endl;
cout << "Beanie $" << beaniecost << endl;
cout << "Bag $" << bagcost << endl;
cout << "Subtotal: $" << subtotal << endl;
cout << "Tax: $" << tax << endl;
cout << "Total: $" << total << endl;
return 0;
}