whats my error here

I have an error coming up on the couts on line 15 and 16 what is wrong here. Also if you see something wrong in my program you can always tell me :)

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
#include<iostream>
#include<fstream>
using namespace std;

char ch;
int x, y, num=0;
void rectangle (char, int, int);
void line (char, int);
void main ()
{
	ifstream file ("\\users\\owen\\desktop\\animals.dat");
	char ch=file.get();
	num=ch-'A'+1;
	x++;
	cout<<line(ch, num);
	cout<<rectangle(ch,x,y); 
	
	
	
}

void line (char ch, int num)
{ int i;
	for (i=1; i<=num; i++)
	cout<<ch;
	cout<<endl;
}

void rectangle (char ch, int x, int y)
{
	line(ch,num);

	for(int j=1; j=y; j++)
	{
		cout<<ch;
		cout<<endl;
	}
}
Lines 15 and 16 should be just
1
2
line(ch, num);
rectangle(ch,x,y);

Also, it should be int main(), not void main().

Why are ch, x, y, and num global variables?
You can just declare them inside of main.
(In general, you should try to avoid using global variables.)
Have you considered the problem is your functions on line 22 and 29.

Some other problems:
1) You are using global variables.
2) You are using using namespace std; instead of std:: prefix
3) you have void as the return type of the main function that returns an int.
4) Line 15 and 16 you should call the function not output the function since they return nothing.
5) line 26 can be appended to line 25.
6) line 31 seems weird since that would make line 15 be called twice when you get to line 16.
7) again line 36 can be appended to line 35. std::cout << ch << std::endl;

Anyways, what are the functions on 22 and 29 supposed to be doing?
well the assignment is to read in from a file of animal names and then output to the console the pattern of their name. For example of the word was dog it would output
dddd

ooooooooooooooo
ooooooooooooooo

ggggggg
ggggggg
ggggggg

thats because d is the first letter in the word and 4th letter in the alphabet then o is 2nd letter in the word and 15th in the alphabet and so on. Im so confused by this and have no idea what to do.

so function line should print out something like "line('a', 10)" aaaaaaaaaa
and rectangle should do the same thing. "rectangle('a', 3, 4)"
aaa
aaa
aaa
aaa
Have you considered doing something like:

1
2
3
4
5
6
7
8
for(int i = 0; i < letterOfWord; ++i)
{
    for(int j = 0; j < letterInAlphabet; ++j)
    {
        std::cout << letter;
    }
    std::cout << std::endl;
}
where would that go? would that be for rectangle?
instead of doing rectangle and line do that?

Otherwise you would have to do something like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void line( ... )
{
    //output one line
    for(int i = 0; i < positionInAlphabet; ++i)
        std::cout << letter;
}

void rectangle( ... )
{
    for(int i = 0; i < positionInWord; ++i)
    {
        std::cout << std::endl;
        line( ... );
    }
}
our professor wants us to use two functions named line and rectangle...

this is what i have now
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
#include<iostream>
#include<fstream>
using namespace std;

char ch;
int x, y, num=0;
void rectangle (char, int, int);
void line (char, int);
void main ()
{
	ifstream fin ("\\users\\owen\\desktop\\animals.dat");
	while(!fin.eof())
	{
	char ch=fin.get();
	y=ch-'a'+1;
	x++;
	line(ch, num);
	}
	cout<<endl;
	
	
}

void line (char ch, int num)
{ int i;
	for (i=1; i<=num; i++)
	cout<<ch;
	cout<<endl;
}

void rectangle( char ch, int x, int y)
{
    for(int i = 0; i < num; i++)
    {
        std::cout << std::endl;
        line( ch, num);
    }
}
Topic archived. No new replies allowed.