C++ user input; outputs a shape

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jan 2006
Posts: 4
Reputation: kisvirag21 is an unknown quantity at this point 
Solved Threads: 0
kisvirag21 kisvirag21 is offline Offline
Newbie Poster

C++ user input; outputs a shape

 
0
  #1
Jan 10th, 2006
I need to write a program that inputs an integer and a character, and outputs a symetrical triangle composed of the character that has the interger of new lines. I can only use 'while' loops at this stage of the course, and I know it has to be nested 'while' loops. I can not use 'for/next' loops. I have done this before in VB6, so I am somewhat exasperated that I can not even get past firstbase with this same problem in C++. And I like C++, strangely enough. Ive spent close to 20 hours trying to figure it out and just cant ;0



the display needs to look something like(minus the -'s that i had to use here as a placeholder):

-----$
----$$$
---$$$$$
--$$$$$$$
-$$$$$$$$$

<< moderator edit: spaces are preserved using [code][/code] tags >>
  1. $
  2. $$$
  3. $$$$$
  4. $$$$$$$
  5. $$$$$$$$$
I set a variable to the same as the inputed integer and i did
k-- to decrease the space by one every time, but i dont know how i should display more than 1 character per line..
---------------------------------------------------------
Any suggestions would be greatly appreciated.
Last edited by Dave Sinkula; Jan 10th, 2006 at 7:14 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,275
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: C++ user input; outputs a shape

 
0
  #2
Jan 10th, 2006
U know how 2 convert a for loop into a while loop now don't u?

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


int main(void)
{
cout<<"enter a integer";
int b;
cin>>b;

cout<<"enter a symbal";
char s;
cin>>s;

int space=b;

int k=1;
for(int i=0; i<b; i++)
{

for(int j=0; j<space; j++)
{
cout<<" ";

}
space--;


for(int m=0; m<k; m++)
{

cout<<s;
}
k=k+2;
cout<<"\n";
}

system("pause");
}
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: C++ user input; outputs a shape

 
0
  #3
Jan 10th, 2006
Don't worry yourself about creating the spaces and aligning into a triangle.... Thanks to C++ you can set the width and fill character of the output
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 4
Reputation: kisvirag21 is an unknown quantity at this point 
Solved Threads: 0
kisvirag21 kisvirag21 is offline Offline
Newbie Poster

Re: C++ user input; outputs a shape

 
0
  #4
Jan 11th, 2006
Thanks guys for the help. while loops can get confuseing as hell with all the brackets and everything.

Thanks again guys
Kisvirag
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 2307 | Replies: 3
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC