15,609,640 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View Python questions
View Javascript questions
View C++ questions
View Java questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Member 8616148 (Top 6 by date)
Member 8616148
9-Dec-13 14:17pm
View
Using 2 lines, and disregarding "main", and making some other assumptions about your true requirement, try this (assuming ternary isn't also forbidden):
std::cin >> n;
std::cout << ((1==n)? "*\n**\n***\n" : ((2==n)? "***\n **\n *\n" : ((3==n)? " *\n **\n***\n" : ((4==n)? "***\n**\n*\n" : ""))));
Member 8616148
9-Dec-13 14:04pm
View
Well, there are some other inconsistencies in your problem statement you should think about as well. A not-so-subtle point I'm trying to get across is that the very first step in solving any programming challenge is to find a clear and specific statements of the requirements and constraints. For example, you say there are "4 patterns", and yet I obviously saw 3 (one line for each, where I think you meant 3 lines for pattern #1, and 3 different lines for pattern #2, etc.) You also state "We haven't learned the for loop in this class and are therefore not allowed to use it." -- but I have no idea what else you "haven't learned", thus I don't know what other constraints there are on solving this problem. Finally, you mention "in one line of code", which is impossible, unless you really stretch the definition of "one line", how are you going to get and store the input variable? How are you going to meet the requirement for "main"?
Member 8616148
9-Dec-13 13:48pm
View
In a console app?
Member 8616148
9-Dec-13 13:47pm
View
That was a statement about "the code you have", not the requirement. Your statement of the requirement was quite specific: "So the goal here is to create four patterns using one line of C++ code. The four patterns are:"
Member 8616148
9-Dec-13 13:34pm
View
I think you need to learn the difference between proportional spaced fonts and others. Try copying what I posted into notepad, then set your font to Courier New. Eliminate the code, and paste each group of stars (asterisks, actually) on a new line. I believe you'll find they match the original requirement quite well.
Member 8616148
9-Dec-13 13:31pm
View
Ahh, then you've learned something. No programmer can "implement" a solution without knowing *all* the requirements. You had not mentioned "user input" in your question.
Show More