there are some problems in my coding which showing errors C2664 and C2562. i have no idea how to fix it...wish someone can point the problems and solutions too...

#include <iostream>

using namespace std;

const int listSize = 10;

void fillArray(int list[],int listSize);
void largest(const int list[],int listSize);
void printArray (const int list[], int listSize);

int main()
{
	int a;
	int b;

	cout<<"please enter the number pancakes that eaten by 10 peoples."<<endl;
	
	fillArray(a,b);
	printArray(a,b);

		return 1;
}

void fillArray(int list[], int listSize)
{
	int index;

	for(index=0;index<listSize;index++)
		cin>>list[index];
}

void printArray(const int list[],int listSize)
{
	int index;

	for(index=0;index<listSize;index++)
		cout<<list[index]<<" ";
}

void largest(const int list[],int listSize)
{
	int index;
	int maxIndex=0;

	

	for (index =1; index<listSize;index++)
		if (list[maxIndex]<list[index])
			maxIndex=index;

	return maxIndex;
}

Dani AI

Generated

— the two compiler messages point to two separate mistakes in your program. As suggested, read the compiler text; as suggested, the docs are useful. Below is a short, actionable diagnosis and a small corrected example.

The causes

  • C2664: the compiler could not convert an argument type for your function call. That happens because a and b in main are plain int variables, but fillArray and printArray expect an array (pointer) and a size.
  • C2562: your largest function is declared void but your definition returns an int (or vice versa). The function signature and the returned value must match.

Minimal fixes

  • In main declare an array (or use std::vector) and pass the array name and the size.
  • Make largest return an int (if it is intended to return the index), update its prototype, and use the returned value in main.

Corrected example (C-style array):

#include <iostream>

const int listSize = 10;

void fillArray(int list[], int size);
void printArray(const int list[], int size);
int largest(const int list[], int size);

int main()
{
    int list[listSize];
    std::cout << "Enter 10 numbers:\n";
    fillArray(list, listSize);
    printArray(list, listSize);
    int maxIndex = largest(list, listSize);
    std::cout << "\nMax at index " << maxIndex << " value " << list[maxIndex] << '\n';
    return 0;
}

Quick tips

  • Prefer std::array<int, listSize> or std::vector<int> for safety.
  • Match prototypes with definitions exactly.
  • Validate input and array bounds before using the index returned by largest.

Recommended Answers

All 2 Replies

Stop writing code that causes C2664 and C2562 errors would be a usable suggestion.

That might mean looking up what the errors mean and either memorizing the descriptions & sulutions or writing them down for future reference.

Press "F1" or google

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.