| | |
C++ user input; outputs a shape
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jan 2006
Posts: 4
Reputation:
Solved Threads: 0
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
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.
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 >> C++ Syntax (Toggle Plain Text)
$ $$$ $$$$$ $$$$$$$ $$$$$$$$$
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.
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*
![]() |
Similar Threads
- user input into a string (C++)
- Tutorial: User Input: Strings and Numbers [C++] (C++)
- error checking of user input (C++)
- Creating a GUI that accepts user input help (Java)
- Need Help With Error Checking User Input (C)
- filtering bad user input (Java)
Other Threads in the C++ Forum
- Previous Thread: DLL's and API's
- Next Thread: To create contact manager using doubly linked list(c++)
Views: 2307 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api array arrays based beginner binary bmp c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete deploy dll download dynamic encryption error file forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library lines linkedlist linker list loop looping loops map math matrix memory microsoft newbie news number output pointer problem program programming project python random read recursion recursive reference return simple sort spoonfeeding stream string strings struct temperature template templates test text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets







