Hello people,
Need help with this code here.
This code suppose to print blocks of char assigned by user with certain rows and column also assigned by user.
For some reason it is giving me error and i don't understand what the problem is
Help will be greatly appreciated.
Thanks!

#include <iostream>
using namespace std;
void func1(int rows,int column,int blocks,char symbol);
void func2(int rows,int column,int blocks,char symbol);
void display ();

int main ()
{
	display();
}

void func1(int &rows,int &column,int &blocks,char &symbol)
{
	cout << "Please enter Char: ";
	cin >> symbol;
	cout<< "Please enter the number of Blocks(Please enter between 3 and 10): ";
	cin >> blocks;
	if (blocks < 3 || blocks > 10)
	{
		do
		{
			cout << "You entered value out of range please enter the value between 3 and 10: ";
			cin >> blocks;
		}
		while (blocks < 3 || blocks > 10);
	}
	cout << "Please enter the numbe of rows: ";
	cin >> rows;
	if (rows < 1 || rows > 5)
	{
		do
		{
			cout << "You entered value out of range please enter the value between 1 and 5: ";
			cin >> rows;
		}
		while (rows < 1 || rows > 5);
	}
	cout << "Please enter the number of columns: ";
	cin >> column;
	if (column < 5 || column > 50)
	{
		do
		{
			cout << "You entered value out of range please enter the value between 5 and 50: ";
			cin >> column;
		}
		while (column < 5 || column > 50);
	}
}

void func2 (int rows,int column,int blocks,char symbol)
{
	for (int row = 0; row < rows; row++){
		for (int block = 0; block < blocks; block++) {
			for (int col = 0; col < column; col++) {
				return (symbol);
			}
			cout<<"\t";
		}
		cout << endl;
	}
}

void display ()
{
	int rows,column,blocks;
	char symbol;
	func1 (rows,column,blocks,symbol);
	func2 (rows,column,blocks,symbol);
}

Recommended Answers

All 6 Replies

What is the error? What is the expected output? What is the current output?

Error 1 error C2668: 'func1' : ambiguous call to overloaded function
2 IntelliSense: more than one instance of overloaded function "func1" matches the argument list:

These are the errors i get!


And for line 56. I have code as : cout << symbol;


expected out put:

***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****

This is the output if user inputs 4 blocks 5 column and 6 as rows!
let me know if anything else.

Thanks.

1) Line 56:

return (symbol);

you can't return something in a void function.

2) Your ambiguous function is because you declare it like:

void func1(int rows,int column,int blocks,char symbol);

and define it like

void func1(int &rows,int &column,int &blocks,char &symbol)

(Note that one has &'s and the other doesn't). These must match exactly.

3) You should always use more descriptive function names. Func1 and func2 doesn't really help anyone know what is going on :)

David

Thanks for the help but this still doesn't resolve the problem! for the last function named
void display()
line 4 it is giving me error for func1 and func2

These are the errors I get


Error 1 error C2668: 'func1' : ambiguous call to overloaded function
68 1 Proj4_1_V1
Error 2 error C2668: 'func2' : ambiguous call to overloaded function
69 1 Proj4_1_V1
Error 3 IntelliSense: more than one instance of overloaded function "func1" matches the argument list:
68 2 Proj4_1_V1
Error 4 IntelliSense: more than one instance of overloaded function "func2" matches the argument list:
69 2 Proj4_1_V1

And this is the whole code again (Updated)

#include <iostream>
using namespace std;
void func1(int rows,int column,int blocks,char symbol);
void func2(int rows,int column,int blocks,char symbol);
void display ();

int main ()
{
	display();
}

void func1(int &rows,int &column,int &blocks,char &symbol)
{
	cout << "Please enter Char: ";
	cin >> symbol;
	cout<< "Please enter the number of Blocks(Please enter between 3 and 10): ";
	cin >> blocks;
	if (blocks < 3 || blocks > 10)
	{
		do
		{
			cout << "You entered value out of range please enter the value between 3 and 10: ";
			cin >> blocks;
		}
		while (blocks < 3 || blocks > 10);
	}
	cout << "Please enter the numbe of rows: ";
	cin >> rows;
	if (rows < 1 || rows > 5)
	{
		do
		{
			cout << "You entered value out of range please enter the value between 1 and 5: ";
			cin >> rows;
		}
		while (rows < 1 || rows > 5);
	}
	cout << "Please enter the number of columns: ";
	cin >> column;
	if (column < 5 || column > 50)
	{
		do
		{
			cout << "You entered value out of range please enter the value between 5 and 50: ";
			cin >> column;
		}
		while (column < 5 || column > 50);
	}
}

void func2 (int &rows,int &column,int &blocks,char &symbol)
{
	for (int row = 0; row < rows; row++){
		for (int block = 0; block < blocks; block++) {
			for (int col = 0; col < column; col++) {
				cout << symbol;
			}
			cout<<"\t";
		}
		cout << endl;
	}
}

void display ()
{
	int rows,column,blocks;
	char symbol;
	func1 (rows,column,blocks,symbol);
	func2 (rows,column,blocks,symbol);
}

Look at #2 in my last post. You did not change this.

commented: Helped a lot! Soleved the problem. +1

Thanks dude! Very helpful!

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.