what is the problem here

So i have a program that should spit out a list of letters and numbers depending on the word in the file.
like if the first word is dog it should print out
dddd

ooooooooooooooo
ooooooooooooooo

ggggggg
ggggggg
ggggggg

because d is the first letter in the word and then 4 letters in the alphabet and o is the second letter in the word and then 15 in the alphabet and g is third letter and 7th in the alphabet. I have some code wich might be wrong but here it is
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++;
	rectangle(ch, x, y);
	line(ch, num);
	}
	
	
}

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++)
    {
        cout << endl;
        line( ch, num);
    }
}

and it comes out with blank space in the console and nothing else. Can someone please help me
You have a global "num" variable in there that is confusing you. You need to get rid of it. The reason you aren't seeing any output is because you are trying to print 'num' elements, and 'num' is zero.

I haven't completely fixed your code, but this should help you along.

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

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

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 < x; i++)
    {
        cout << endl;
        line( ch, y);
    }
}

Try to clear out the stuff you don't need.

Oh, also, I read input from stdin (the cin). You should consider doing the same and not hard-coding your datafile's path in your program.

You can get your program to run by simply dragging the datafile and dropping it on your program's exe.

Hope this helps.
Topic archived. No new replies allowed.