Hello jlin55,
PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.
The "Sales" class is better, but not quite there yet. You have a private variable of grosssales, but who does it belong to? You also need to define a constructor and destructor as your comment says. Not sure if the "Sales.h" file is the best place to put line 11, but it is my first thought. I would also write that line as:
constexpr double commision=0.09;//rate given
or just make it "const" if needed. I would also check your spelling of "commission" before you spell it correctly and have a problem trying to figure out where you went wrong.
In main lines 14 - 21 are a good start, but you need some code in the while loop to process your input starting with asking for a name then processing what was entered ending the loop by asking for the sales input where if it is not -1 you will process the new information. My idea:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
cout << "Enter sales In dollar(-1 to end)";
cin >> sales; //input
// write the loop to get more values
// If sales > -1 enter the loop
while (sales != -1)
{
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // <--- Requires the limits header file. Used after std::cin >> var; and before a call to std::getlineto clear the \n fromthe input buffer.
std::cout << "\nEnter name: ";
std::getline(std::cin, name); // <--- Where name is defined as a std::string.
// Code to process the input
// Store in vector
cout << "Enter sales In dollar(-1 to end)";
cin >> sales; //input
}
|
The concept is good, but I have not tested this yet.
You will need to define a vector
std::vector<Sales> anyNameYouLike;
.
The beginning of main would be this:
1 2 3 4
|
#include <iostream>
#include <string>
#include <vector>
#include <limits> // <--- for the std::cin.ignore(...).
|
I will work with your new changes and see if I find anything else.
Hope that helps,
Andy