Hello garza07,
As I worked with the program this is what I came up with:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
#include <iostream>
#include <string>
#include <cctype> // <--- For std::toupper() and tolower().
//using namespace std;
int main()
{
constexpr double APPLES = 1.0;
constexpr double BANANAS = 0.40;
constexpr double ORANGES = 3.0;
constexpr double PEARS = 0.25;
constexpr double GRAPES{ 2.5 };
constexpr double LEMONS{ 0.5 };
char checkout;
char choice;
int A{}, B{}, O{}, P{}, X{}; // <--- Needed initialized and never used.
int a{}, b{}, o{}, p{}; // <--- Can be replaced with "qty".
double qty{};
double subTotal{};
double total{};
std::string name; // <--- The string is empty and does not need initialized.
std::string phone;
std::string address;
std::cout << "Please enter Name: ";
std::cin >> name;
std::cout << "Phone Number: ";
std::cin >> phone;
std::cout << "Address: ";
std::cin >> address;
//Check in
// Missing grapes and lemons and exit.
std::cout << " What would you like to Purchase " << std::endl;
std::cout << " 1. [A]pples 1/lb " << std::endl;
std::cout << " 2. [B]ananas 0.4/lb " << std::endl;
std::cout << " 3. [O]ranges 3/lb " << std::endl;
std::cout << " 4. [P]ears 2.5/lb " << std::endl;
std::cin >> choice;
if (std::toupper(choice) == 'A')
{
std::cout << " How many LBS would you like to buy? " << std::endl;
std::cin >> qty;
subTotal += APPLES * qty;
}
|
This is the beginning and will give you an idea how to change what follows.
What I would do is put most of the program in a do/while or while loop, so that you can continue ordering until you choose to exit. I would also use a switch in place of the if/else if statements.
I added the variable "subTotal" and as you can see in the if block for 'A' it says "+=" otherwise every time you order something it would over wright what you did previous.
Some things you will see different from what you did:
At the beginning of main I have the section that begins with "constexpr" or you could just use "const", the former is the newer version. Since they deal with floating point numbers I made them doubles and the capital letters let you know that it is a constant that can not be changed. Normally I would put these lines above main so they are easy to find when any changes are needed.
The regular variables start with a lower case letter and the rest is lower case letters unless you put to words together then it is called camel case as in "subTotal".
Before you work on the checkout part you need to get the first part working first.
Hope that helps,
Andy