Need help with - cannot convert parameter 1 from 'int' to 'int []

This is a discussion on Need help with - cannot convert parameter 1 from 'int' to 'int [] within the C++ Programming forums, part of the General Programming Boards category; Hey, Im new to programming (less than 3 months into a course) and we have a assignment (no im not ...

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    2

    Need help with - cannot convert parameter 1 from 'int' to 'int []

    Hey,
    Im new to programming (less than 3 months into a course) and we have a assignment (no im not asking you guys to do it for me ) and iv written the below code but i keep getting this error

    C2664: 'input' : cannot convert parameter 1 from 'int' to 'int []'

    Sorry if i look like i have made a mess of the code most likely its all wrong but im new to coding and im finding it hard to wrap my hear around.

    Thanks in advance kv0nza

    Code:
    #include <iostream>
    #include <iomanip>
    
    using namespace std;
    
    
    int input (int qtyStock[], int stockPrice[], int k)
    {
    	cin >> qtyStock[6];
    	cin >> stockPrice[6];	
    }
    void heading ()
    {
    	  cout << "-------------------------------------------------------------------------" << endl;
    	  cout << "Stock Item" << setw(15) << "Quantity" << setw(10) << "Unit Price" << setw(15) << "Total Value" << endl;
    }
    int outputGross(int &gross)
    {
    }
    int computation (int qtyStock[], int stockPrice[], int stockValue[])
    {
    }
    int output (int qtyStock[], int stockPrice[], int stockValue[], int gross, int m)
    {
    }
    
    
    
    int main()
    {
    
    	int qtyStock[6] = {0,0,0,0,0,0};
    	int stockPrice[6] = {0,0,0,0,0,0};
    	int stockValue[6] = {0,0,0,0,0,0};
    	int k;
    	int gross;
    
    	for (int k = 0; k < 6; k++)
    		{
    			input(qtyStock[k], stockPrice[k], k);
    			gross += computation(qtyStock[k], stockPrice[k], stockValue[k]);
    		}
    
    	heading();
    
    	for (int m = 0; m < 6; m++)
    		{
    			output(qtyStock[m], stockPrice[m], stockValue[m], gross, m);
    		}
    
    	outputGross(gross);
    
    	system("pause");
        return 0;
    }
    Last edited by kv0nza; 05-22-2010 at 08:30 PM. Reason: coding code

  2. #2
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Not sure about your specific error since you didn't really say what line it was on but where you are doing this:
    Code:
    	cin >> qtyStock[6];
    	cin >> stockPrice[6];
    What is it you are trying to do exactly? Because the thing is, these integer arrays are 6 elements in size and are zero based so only 0-5 are valid elements. qtyStock[6] will overwrite some bit of your memory, probably your stack with less than savory results....so you are allocating room for 6 integers and using cin to read....what? 1 element? and which element of the array is it meant for?
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    2
    Quote Originally Posted by jeffcobb View Post
    Not sure about your specific error since you didn't really say what line it was on but where you are doing this:
    Code:
    	cin >> qtyStock[6];
    	cin >> stockPrice[6];
    What is it you are trying to do exactly? Because the thing is, these integer arrays are 6 elements in size and are zero based so only 0-5 are valid elements. qtyStock[6] will overwrite some bit of your memory, probably your stack with less than savory results....so you are allocating room for 6 integers and using cin to read....what? 1 element? and which element of the array is it meant for?
    Im trying to make a program that asks for 6 elements in the qtyStock array and then do the same for stockPrice array then feed that back into the for loop.

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    6,425
    The complaint from the compiler would be occurring in main(), in the first loop.

    The line
    Code:
    input(qtyStock[k], stockPrice[k], k);
    is trying to pass integral values where an array of integers (or, depending on context, a pointer) is expected.

    The use of index 6 inside the function is also a problem as others have mentioned. However that will not cause a compiler error. It may (depending on how input() is called) cause undefined behaviour, often visible in the form of a program crash.
    Right 98% of the time, and don't care about the other 3%.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can anyone help?
    By javalurnin in forum C Programming
    Replies: 11
    Last Post: 12-02-2009, 05:02 AM
  2. Game Won't Compile
    By jothesmo in forum C++ Programming
    Replies: 2
    Last Post: 04-01-2006, 03:24 PM
  3. Need help understanding info in a header file
    By hicpics in forum C Programming
    Replies: 8
    Last Post: 12-02-2005, 11:36 AM
  4. getting a headache
    By sreetvert83 in forum C++ Programming
    Replies: 41
    Last Post: 09-30-2005, 05:20 AM
  5. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21