I need to create a triangle in C++ that will take the user inputted letter (capital) and then create a triangle that will look like. I can only use nested loops NO arrays or strings
Enter a letter: F
F
FE
FED
FEDC
FEDCB
FEDCBA
here is the code i have so far i am creating a triangle but not exactly the one i require
cout << "\nWould ye' like to enter another letter? (Y/N) ";
cin >> ans;
}while(toupper(ans) == 'Y');
list->next = NULL;
list = head_ptr;
int j=1;
while(list)
{
for(int i=0; i<j && list; i++)
{
cout << list->letter;
list = list->next;
}
cout << endl;
j++;
}
list = head_ptr;
node temp;
while(list)
{
temp = list;
list = list->next;
delete temp;
}
return0;
}
This code creates a 'linked-list' of nodes that contain space for 1 char per node. After the user is prompted to enter several letters, the list is traversed (starting from the head pointer) and displayed to the screen in a tree type manner.
This is untested code, so it might contain simple/easy to fix errors.
Last edited by Clinton Portis; Oct 28th, 2009 at 3:49 pm.
Thanks fro your help
my only problem is that i am so new at this and have yet to learn about linked lists of char. there as to be a stupid way for newbies like me, i do have a class tomorrow and can ask the teacher, and i will keep on trying. if you try my code it also does not stop at letter it keeps going on through the ASCII chart
The requirements for this assignement approach an intermediate level of programming since we cannot use arrays or <string> class objects. Being that we are unable to use arrays, we cannot use 'c-strings' (char arrays). So what's left?
Our options include: STL containers and linked lists or just create a ton of singular char variables and hope we have enough for user input. Another option would be to write all the char variables to a file.
I'm open to suggestions, I think the method I used was probably the most primitive of options that I could think of.
Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.
This thread is more than three months old
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.