whats my problem

I have a list of animal names and i have to output them in a certain list
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 which 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
39
40
#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; 
	fin.open ("\\users\\owen\\desktop\\animals.dat");
	char ch=fin.get();
	while(!fin.eof())
	{
		x=ch-'a'+1;
		y++;
		rectangle(ch, x, y);
		line(ch, num);
		char ch=fin.get();
	}
	
	
}

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);
    }
}
Can you specify what do you want; clarify your problem? I didn't got any word you said.
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
#include <iostream>
#include <string>
#include <cctype>

void line( char c, std::size_t num )
{
    for( std::size_t i = 0 ; i < num ; ++i ) std::cout << c ;
    std::cout << '\n' ;
}

void rectangle( char c, std::size_t width, std::size_t height )
{
    for( std::size_t i = 0 ; i < height ; ++i ) line( c, width ) ;
    std::cout << '\n' ;
}

int main()
{
    const std::string alphabet = "abcdefghijklmnopqrstuvwxyz" ;

    std::string animal = "Tiger" ;

    for( std::size_t i = 0 ; i < animal.size() ; ++i  )
    {
        char c = animal[i] ; // get the character

        if( std::isalpha(c) ) // if it is alphabetic
        {
            // get its position in the alphabet (a==1)
            std::size_t pos = alphabet.find( std::tolower(c) ) ;

            rectangle( c, pos+1, i+1 ) ; // width pos+1, height i+1
        }
    }
}

http://coliru.stacked-crooked.com/a/cf2b7cb466edca9e
Topic archived. No new replies allowed.