Multiple file program help

Hello! I am trying to write a program that has three files, two .cpp and one .h
one of the .cpp files is details the function for the .h and im having trouble getting it to compile. I know it has to do with using return and i dont know how the code shoud look.
Below is the functions .cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

#include "figures.h"

int filledSquare(int a)
{
	for  (int b = 0; b < a; b++)									//first figure
	{
		for (int c = 0; c < a; c++)
			cout << "*";
		cout << endl;
	}
	cout << endl;
}
int leftTriangle(int a)
{
	return (int b = a; b > 0; b--)									//second figure
	{
		for (int c = 0; c < b; c++)
			cout << "*";
		cout << endl;
	}
	cout << endl;
}
int rightTriangle(int a)
{
return (int b = 0; b < a; b++)									//third figure
{
	int s = a - b;                                            //calculates number os stars to print
	for (int c = 0; c < b; c++)
		cout << " ";
	for (int c = 0; c < s; c++)
		cout << "*";
	cout << endl;
}
cout << endl;
}
int hollowSquare(int a)
{
return (int b = 0; b < a; b++)									//fourth figure
{
	int s = a - 2;
	if (b == 0 || b == (a - 1))
	{
		for (int c = 0; c < a; c++)
			cout << "*";
		cout << endl;
	}
	else
	{
		cout << "*";
		for (int c = 0; c < s; c++)
			cout << " ";
		cout << "*";
		cout << endl;
	}
	cout << endl;
}

.h file
1
2
3
4
int filledSquare(int);
int leftTriangle(int);
int rightTriangle(int);
int hollowSquare(int);

main .cpp file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

#include <iostream>
#include <string>
#include "figures.h"

using std::cout; using std::cin; using std::endl;
std::string line;

int a;

int main()
{
	cout << "1. Square" << endl;
	cout << "2. Left Triangle" << endl;
	cout << "3. Right Triangle" << endl;
	cout << "Choose a function: " << endl;
	cin >> a;
	if (a == 1)
	{
		char sq;
		cout << "Filled of hollow [f/h]: ";
		cin >> sq;
		while(std::cin >> sq);
		if (sq, "f")
		{
			cout << filledSquare;
		}
		else if (sq, "h")
		{
			cout << hollowSquare;
		}
	}
}
Last edited on
I changed the function .cpp so that there is no return on each function. So now the only errors im receiving are from those functions not returning a value. I'm not sure how to write that part in the functions themselves.
Shameless self bump, really stuck on this. Also i believe that for choosing a filled or hollow square, i do not have the correct code to have the user enter f for filled or h for hollow.
Last edited on
Topic archived. No new replies allowed.