Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

Newb coder needs help c++


  • Please log in to reply

#1
SlitNek

SlitNek

    Member

  • Member
  • PipPip
  • 38 posts
I have been teaching myself out of a book with C++ and i am a bit stuck on something, it will be pritty simple for the most part a few lines or so, i have to print this to the screen....

+_____+
_+___+
__+_+
___+

imagine the _ are not there these represent a space 'whitespace'
this is a console application btw

this cannot be done with cout's it must be done with for loops, here is a sample of the rest of the patterns if you can get the drift of the code style

#include <iostream>
#include <iomanip>
using namespace std;

int main ()
{
int col, row;
char mychar = '+';

//Pattern 1
for (col=1; col <= 5; ++col)
{
cout << endl;
for (row=0; row < col; ++row)
{
cout << mychar;
}
}

//Pattern 1 part 2
for (col=0; col <= 5; ++col)
{
cout << endl;
for (row=4; row >= col; --row)
{
cout << mychar;
}
}

//Pattern 2
cout << endl;
for (col=0; col < 5; ++col)
{
cout << endl;
for (row=0; row < 4 - col; ++row)
{
cout << " ";
}
for (row=0; row < 2 * col + 1; ++row)
{
cout << mychar;
}
}

//Pattern 3
cout << endl;

return 0;
}

Edited by SlitNek, 13 April 2006 - 03:50 PM.

  • 0

Advertisements







Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP