Here are my error messages:

! "printStock(int, int)", referenced from:
_main in main.o
_main in main.o
! "Sales(int, int, double)", referenced from:
_main in main.o
Symbol(s) not found

Here is my code:

#include <iostream>
#include <cmath>
#include <iomanip>
#include <fstream>
using namespace std;

void printStock(int,int);
double Sales(int,int,double);
int main () 
{
	
    ifstream transInfo;
	transInfo.open("transinfo.txt");
	
	if(!transInfo.is_open()) {
		cout << "File was not opened correctly" << endl;
		cout << "program halted";
		return 0;
	}
	
	int transtype, autonumb, units, i;
	
	int inv[10]={0,0,0,0,0,0,0,0,0,0};
	for (i=0; i<10; i++)
		inv[i]=i;
	
	printStock(inv[10],10);
	
	transInfo >> transtype >> autonumb >> units;
	for (i=0; i<10; i++){
		
		if (transtype==1) {
			if (inv[autonumb]>=units) {
				inv[autonumb]-=units;
				cout << "Sell " << units << " units of car " << autonumb << endl;
			}
			else cout << "REJECTED: Insufficient Stock" << endl;
		}
		
		else if (transtype==2) {
			inv[autonumb]+=units;
			cout << "Receive " << units << " units of car " << autonumb << endl;
		}
		
		else cout << "INVALID TRANSACTION CODE" << transtype << endl;
		
		transInfo >> transtype >> autonumb >> units;
	}
	
	cout << endl;
	printStock(inv[i],10);
	cout << "\n\nTotal potential income: " << Sales(inv[i],10,10000) << endl;
	
	transInfo.close();
    return 0;
}

void printStock (int v[], int n) {
	for (int i=0; i<n; i++)
		cout << i << v[i];
	return;
}

double Sales (int v[], int n, double cost) {
	int autos=0;
	for (int i=0; i<n; i++)
		autos+=i;
	int val=autos*cost;
	return val;
}

I don't know what's wrong so I don't know exactly what to ask. I need some diagnostic help in the first place. So I need all kinds of help, any I can get. Thank you.

The implementation of printStock() and Sales() differ from their declaration at the top of the file. The declaration for printStock() is void printStock(int, int) whereas the implementation is void printStock(int[], int) . Ditto for Sales().

Look carefully at the prototypes. Do they match the actual function? Do your calls match what the function is expecting?

Your function prototypes are:

7. void printStock(int,int);
8. double Sales(int,int,double);

Your function definitions are:

58. void printStock (int v[], int n) {
	for (int i=0; i<n; i++)
		cout << i << v[i];
	return;
}
 
double Sales (int v[], int n, double cost) {
	int autos=0;
	for (int i=0; i<n; i++)
		autos+=i;
	int val=autos*cost;
	return val;
70. }

...

Take line 58 and line 64, and replace line 7 and 8 with them.

7. void printStock(int,int);       --->    void printStock (int v[], int n);
8. double Sales(int,int,double);   --->    double Sales (int v[], int n, double cost);

Then attempt to recompile your program.

Ok so I tried all this, didn't work

New error: "Invalid conversion from 'int' to 'int*'"
Lines 27, 51, 52

Hmm.. We're passing in an integer when it should be a pointer to an integer... In that case try changing the function prototypes and the beginning of the declarations to

void printStock (int v*, int n);
double Sales (int v*, int n, double cost);

Hmm.. We're passing in an integer when it should be a pointer to an integer... In that case try changing the function prototypes and the beginning of the declarations to

void printStock (int v*, int n);
double Sales (int v*, int n, double cost);

He says he fixed all that.

Yeah he fixed the prototypes so they match, but now he's reporting an error where the variable types won't work properly

Yup that's the problem please help me

Yup that's the problem please help me

Then explain in detail and post code.

#include <iostream>
#include <cmath>
#include <iomanip>
#include <fstream>
using namespace std;

void printStock (int v[],int n);
double Sales (int v[], int n, double cost);
int main () 
{
	
    ifstream transInfo;
	transInfo.open("transinfo.txt");
	
	if(!transInfo.is_open()) {
		cout << "File was not opened correctly" << endl;
		cout << "program halted";
		return 0;
	}
	
	int transtype, autonumb, units, i;
	
	int inv[10]={0,0,0,0,0,0,0,0,0,0};
	for (i=0; i<10; i++)
		inv[i]=i;
	
	printStock(inv[10],i);
	
	transInfo >> transtype >> autonumb >> units;
	for (i=0; i<10; i++){
		
		if (transtype==1) {
			if (inv[autonumb]>=units) {
				inv[autonumb]-=units;
				cout << "Sell " << units << " units of car " << autonumb << endl;
			}
			else cout << "REJECTED: Insufficient Stock" << endl;
		}
		
		else if (transtype==2) {
			inv[autonumb]+=units;
			cout << "Receive " << units << " units of car " << autonumb << endl;
		}
		
		else cout << "INVALID TRANSACTION CODE" << transtype << endl;
		
		transInfo >> transtype >> autonumb >> units;
	}
	
	cout << endl;
	printStock(inv[i],10);
	cout << "\n\nTotal potential income: " << Sales(inv[i],10,10000) << endl;
	
	transInfo.close();
    return 0;
}

void printStock (int v[], int n) {
	for (int i=0; i<n; i++)
		cout << i << v[i];
	return;
}

double Sales (int v[], int n, double cost) {
	int autos=0;
	for (int i=0; i<n; i++)
		autos+=i;
	int val=autos*cost;
	return val;
}

Errors:

Line 7:

! Expected primary-expression before ']' token
! Array bound is not an integer constant
! Too many arguments to function 'void printStock(int)'
! Too many arguments to function 'void printStock(int)'

Line 8:

! Expected primary-expression before ']' token
! Array bound is not an integer constant
! Too many arguments to function 'double Sales(int, double)'

Lines 27, 51, 52:

! At this point in file

????? I've tried switching the variables/declarations/whatever like everyone here suggested. If I remember correctly it only gave more errors, but either way it didn't help at all...

Thanks anyway though guys errors are friggen frustrating

When sales() returns a double, why are you computing and returning an integer?

Also, look at the output from printstock(). You are concatenating i and val, which at best is confusing for the viewer. I haven't got to main() yet...

That makes sense, you're right, thanks. The first part, I mean (re: Sales). I don't know what you mean about "the output from printStock()"? Explain further?

Here's my assignment too, maybe this will help?...

Assume that BROOKLYN AUTOS maintains data on up to 10 cars on a daily basis (these autos are numbered 0-9). This information is maintained in an array inv which stores the current information for each auto. For example if inv3 = 20, this means that there are 20 autos of type 3 currently in stock. Initially, all autos have 0 on hand.

1. Write a function printStock. This function accepts the array inv and the number of autos and prints a chart showing the auto number along with the current inventory.

2. Write a function Sales. This function calculates the total value of all autos on hand. The function accepts the array inv, the number of autos, and the cost per auto [for purposes of this assignment, we will assume that all autos are sold at the same price]. The function returns the total income potential if all the autos were sold. (Hint: Compute the total number of autos and multiply by the price.)

3. Write a main function as follows:
- Create the array inv and initialize all elements to 0.
- Create a file transInfo. This file contains lines of data, each line representing either a purchase or a return for a particular auto. You are to create the file on disk with the data shown below. Define and open the file (for input) in your main function.
- Call the function printStock (to print the current status -- all autos have 0 on hand).
- Process the data in transInfo as follows: Each data line contains three items of information: Transaction type (1 = sale, 2 = return); auto number (an integer 0-9); number of units (sold or receipt). If the transaction is a receipt, then add the number of autos to the corresponding element of the inv array; if the transaction is a sale, then subtract the number of seats from the corresponding auto inventory. For each transaction, print a log (message) describing the action that you took. Note: If an attempt is made to purchase more autos than are currently available, that transaction should be rejected (and noted on the log). Similarly, if an invalid transaction code is entered, that transaction should be rejected (and noted on the log). This step should end when there is no data remaining.
- Call the function printStock
- Call the function Sales with an appropriate message (to print the total income for all autos). For purposes of this call, assume the price of a single auto is $10000.00.

That makes sense, you're right, thanks. The first part, I mean (re: Sales). I don't know what you mean about "the output from printStock()"? Explain further?

Your code

void printStock (int v[], int n) {
	for (int i=0; i<n; i++)
		cout << i << v[i];
	return;
}

Has no space between the output of the variable 'i' and the value of v. For readability, something like this may be better:

void printStock (int v[], int n) {
	for (int i=0; i<n; i++)
		cout << i << " " << v[i] << endl;
	return;
}

That will put a space between the index 'i' and the value 'v', as well as placing each entry on a separate line. In your example, you would just have a single line, with the index and values all jammed together, such as:

010111212313...

Not particularly helpful, IMO.

Okay that's true I know right now I'm just trying to get it to work though, and then I polish it up. Obviously. I make it nice. But it's got to work first.

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.