|
-
October 12th, 2005, 10:16 PM
#2
Re: Errors in my program
Most of your syntax errors should be obvious from the error messages given when you try to compile your code. For example, here:
Code:
double addDrop(regularPrice, VIPPrice, qty, double& totalAmt, double& totalSavings);
Every variable in a function prototype like this must have its type specified, and yet you have not specified the type of regularPrice, VIPPrice, or qty. You make the same error in many places throughout your program. You also have a few places where you're attempting to use variables without having declared them first. You have cases where you're attempting to call a function with the incorrect number of parameters, or are trying to pass the wrong type of parameters. I think you probably just need to read up on basic syntax a little more closely. An example program:
Code:
// Function prototype - lays out the function name, return type, and parameter list.
// Ends with a semicolon. Variable types are required; names are optional.
int f(int a, int b);
// In other words, writing this:
//
// int f(int, int);
//
// would be an acceptable alternative, but writing this:
//
// int f(a, b);
//
// is wrong, because the compiler doesn't know what a and b are supposed to be.
int main()
{
int num1 = 1;
int num2 = 2;
// When calling a function you must use the correct number and types of parameters.
f(num1, num2);
return 0;
}
// Function implementation. No semicolon following the header.
int f(int a, int b)
{
// Must return a value of the correct type.
return a + b;
}
Also, you didn't post your entire code. It cuts off abruptly at the end. Finally, for future reference, when posting code please enclose it in the [code]...[/code] tags. This will preserve formatting as in the example above.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|