hi rayjed,
First of all, you have to know that C++ is a case sensitive language. The word "Using" is not the same as "using". C++ will flag the first one as bad and the second as good. Keep this in mind ALWAYS! (same goes with "Int main" it is suppose to be "int main")
Next thing you made mistakes on are the ones that all new programmers tend to make. Bad variable names, too many variables, and not keeping variable names consistent through the program.
When making a variable ask yourself what purpose is this variable going to be for. Then name the variable with a good name that makes it very easy to read. If the variable is going to hold the number of accounting books sold, name the variable "accountingSold" makes sense right? It will help you, and others reading your code, remember what the variable is and when used in calculations it will almost sound like english sentences.
For instance
totalSold = accountingSold + businessSold; would simply read "the total sold is equal to the number of accounting books sold plus business books sold"
You had a problem too about keeping variables straight. You had a1, b2, c3 defined but then tried to use "a1, b1, c1" which b1 and c1 are not defined. Using very good names will help you keep this straight too and prevent this error.
Then when you went to print the lines at the end, you didn't actually include the variables in the print lines so their values would never be displayed. So see how I did it below and that will help you.
Lastly, no where in the description did it say you needed a subtotal. So don't put anything in for that! You can simply calculate the total based on the number of books and their price. You would only need a subtotal if later they asked you to calculate tax.
Below is the first assignment redone (not bullet proof mind you because it does no error checking) but should give you an idea of how things are put together.
cpp
// prb01-1.cpp
// This program calculates the total charge for all books purchased
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
// Declare the variables
// Declare variables to hold number of books sold.
int accountingSold = 0, businessSold = 0, cisSold = 0, draftingSold = 0;
// Declare variables to hold the price of each type of book.
float a1 = 10.00, b2 = 20.00, c3 = 30.00, d4 = 40.00;
// Declare variable to hold the sum.
int sum = 0;
// Declare variable to hold the total.
float total = 0.00;
// Obtain the input data
// Collect the data and put the number into each of our books sold variables.
cout << "Enter the number of accounting books sold: ";
cin >> accountingSold;
cout << endl;
cout << "Enter the number of business books sold: ";
cin >> businessSold;
cout << endl;
cout << "Enter the number of cis books sold: ";
cin >> cisSold;
cout << endl;
cout << "Enter the number of drafting books sold: ";
cin >> draftingSold;
cout << endl;
// Do the calculations
// Books sold times price, added together for the total.
// Simply add together our sold variables to get the sum.
sum = (accountingSold + businessSold + cisSold + draftingSold);
total = (accountingSold * a1) + (businessSold * b2) + (cisSold * c3) + (draftingSold * d4);
// Display the results
// Notice how we put the variables into the lines to print their value.
cout << "Number of accounting books: " << accountingSold << endl;
cout << "Number of business books: " << businessSold << endl;
cout << "Number of cis books: " << cisSold << endl;
cout << "Number of drafting books: " << draftingSold << endl;
cout << "Sum of books: " << sum << endl;
cout << "Total charge: $" << total << endl;
return 0;
}
As for compiling, if you are doing simple C++ then you might want to switch to a compiler like Microsoft Visual C++ .NET 2008 Express edition. I find it a tad bit easier to use when creating standard C++ projects than back in version 6.0. That is a pretty old version and while it will work for C++, it is a bit harder to work with.
You can download visual c++ .net 2008 express for free (completely free) at the link below...
Microsoft Express Editions 2008When creating a new project follow these steps...
1) Start up visual C++
2) On the left you will see "create project" Click that
3) In the window that pops up, go to "general" on the left tree
4) In the right pane you should then see "empty project" select that.
5) After the project starts up, you will again see a tree on the left in a pane called "solution explorer". Right click the folder that reads "source files"
6) A menu pops up and go to "Add >> new item"
7) In that window select "CPP file" and give it a name.
8) click ok
9) Now you will see a blank cpp file. Put your c++ code in there and hit the save icon.
10) Lastly, press ctrl + f5 to start the compiling. All errors in your code will appear as error messages in a window pane at the bottom of the screen. You can often times copy that text from the pane to the board here and we can help you diagnose the problems along with your code (which you should provide as well).
That is a basic idea of how you could compile your c++ programs and get running.
Hope this proves helpful to you. If it does, don't forget to select the "This post was helpful" link at the bottom.
Enjoy!
"At DIC we be c++ compiling code ninjas in .NET 2008 Exress, just don't get us pissed or we will 'express' our ideas in another way!"