Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
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