Hi,

im a student taking information tech. and im a newbie in this forum...
i need help on the machine problem that my prof gave me...
please help me i cant figure out what codes do i use..:confused:


the number 5 is user's input...
the output is this...

Input a Number: 5
a
bc
cde
defg
efghi

please help me...
thanks... in advance...:)

thanks sir...
sorry for my first post...
i tried to figure it out last tuesday...
but i guess idont have still the knowledge to get it...:'(

#include <cstdlib>
#include <iostream>
#include <string.h>
using namespace std;

char z[50];
char x[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char y[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
int a=0,b=0,g=0;

int main(int argc, char *argv[])
{
    system("cls");
	cout<<"Input Number: ";
	cin>>g;
	for (;g>0;g--)
{
    	 a=+g;
	 b=a;
	cout<<endl<<y[a]<<y[b]<<z;
}	
    system("PAUSE");
    return EXIT_SUCCESS;
}

thanks for the concern sir...:)

Well, hard-coding the whole alphabet in your program is possible, but there's another way, without needing to hard-code the whole alphabet in your program, let me describe it:

Input a Number: 5
a
bc
cde
defg
efghi

The above sample run of the program makes me think about the fact that you'll need a char variable for holding the 'current' letter.
First: the current letter is 'a', then it's 'b', after that it becomes 'c', and so on.
When you take this approach, you only need to display alphabet characters, starting from the current letter each time.
What do I also see? Hmm, if the user inputs 5, I see the program prints five lines, so you'll need a for-loop which runs the same amount of times, as the number the user entered (if the user enters 5, the loop runs five times, if the user enters 7, the loop will run 7 times).
Another thing I see is that each time, the length of the line increases with one, in the first loop run, we want the line to be of length 1, in the second loop run we want the line to be of length 2, etc...
You can achieve this by running another for-loop inside the outer for-loop (yes indeed! a loop inside another loop), you let this loop run and set the condition so that it will stop when its index is higher than the outer's loop index.
(that is: you let that loop run as long as the inner loop's index variable is less than or equal to the outer's loop index variable).

Edit::
I marked the 'current characters' in green (see the quote), instead of a char variable which holds the current character, you could also just use the outer's loop index variable, do some operations (which you have to find out) on it, and cast the result to a char.

Edit::
To illustrate better what I mean, I'll provide you with some sample code from which you could start:

for(int i=0; i<num; i++) {
   for(int j=0; j<=i; j++) {
      /* 
           Your code here
      */
   }
}

Oh my GOD!!
sir thank you very much!!
i analyze what you make say!
and it works!:-O

maybe i will not post the code...
because i think lot of my blockmates will copy it without trying it...
i want to help them but im againts in copying of the code... they don't deserve to graduate if they just copy and try to cheat...:sad:

by the way,
thank you very much sir you help me a lot!!
i hope if i gonna need some help again people in this forum will help me!!^_^v
i'm happy to be a member on this forum...:)
(sorry in my english i'm not good at it:icon_cheesygrin: )
but i gonna try my best to help others!!!
thanks again sir!!:icon_biggrin:

Comments
I'm glad you could solve it :)
This question has already been answered. Start a new discussion instead.