hi every1 i also need help with my assignment
im supposed to find the errors and explain how to correct it
heres the program:


//question 3a

#include <iostream>
using namespace std;

int main ( )
{
int nrLuggagepieces;
float mass, total mass;
int averageMass;

// initialize
totalMass = 0;
// loop
while (mass > 0)
{
//input next mass
cout << "Please enter mass of next piece of luggage (0 to end): ";
cin >> mass;
//update totals 
totalMass += mass;
nrLuggagePieces++;
}                   //end of whileloop
// display number of pieces of luggage
cout << "The number of pieces is " << nrLuggagePieces << endl;
//average       (0.5 is added in order to round off)
if (nrLuggagePieces > 0)
averageMass = int (totalMass / nrLuggagePieces + 0.5);
else
averageMass = 0;
cout << "The average mass of a piece of baggage is"
     << averageMass <<endl;

return 0;
}

Did you try to compile it? Or are you allowed to do that?

Read the line one at a time, pay close attention to spelling and variable initialization. I can spot three mistakes right away.

i did compile it but it came up with errors

Of course it did ! That's what your assignment is all about. From what you posted all you are required to do is identify the errors and explain how to correct them. Actually correcting them and recompiling will help a lot because some errors may be hidden or not appear until previous errors have been fixed. And compilers often spit out a bunch of errors for the same line. Just concentrate on the first error for any given line because that is normally the problem.

but i don't know how to!!!i don't know whats wrong

its my first year at university.....doing it through correspondence so i don't get help from lecturers

Hi Nimz. When declaring variables, there's a few rules. Scroll down to Names in C++ here
http://www.functionx.com/cppcli/variables/Lesson03.htm

See then if you can spot anything wrong with how the variables are declared in your program on lines 6, 7, 8.

After that, check the rest of the program, and see if the variables that are used are declared properly.

look at the first error message. What does it say? It tells you the line number that the error occurred on what what's wrong with it.

Still confused? Post the first few error messages here so that we can see them too.

warning in function main 'int main[]
expected init-declarator before ''mass''
'totalMass'undeclared

[Build Error]

Thanks for all the help people. Im just going to submit it with all the wrong stuff bcoz i don't know whats going on.

Did you read Colin's post ^^^ ? He gave you many hints. That error means that totalMass is not declared anywhere. Check the spelling very very carefully on line 7 of the code you previously posted.

Thanks for all the help people. Im just going to submit it with all the wrong stuff bcoz i don't know whats going on.

You give up too easily.

have you really looked through the code??? for starters dont you think total mass and totalMass are not the same?? you cant use spaces to while declaring variables..use totalMass or total_mass..look through ur error messages and look at the code you cant fail to correct other errors

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.