LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 10-08-2012, 03:29 PM   #1
carlosk711
Member
 
Registered: Sep 2012
Posts: 52

Rep: Reputation: Disabled
Trying to make a grid for fun, what am I doing wrong?


Code:
#include <iostream>
using namespace std;
int main()
{

    int row, column;
    row == 0;
    column == 0;
    {if (((row % 2) == 0)
    (while ((row <= 9)
    {while ((column <= 17);
    cout << "-";
    column ++)}));
    row ++ ;
    cout << endl) ;

    else if ((row <= 9)
    while ((column <= 17)
    {cout << "|   " ;
    column = column + 4));
    row ++;}
    return 0;
}}
I'm trying to make it look like this:
-----------------
| | | | |
-----------------
| | | | |
-----------------
| | | | |
-----------------
| | | | |
-----------------

I want to do it using while and for loops too.
Help is much appreciated!!

Here are errors I'm getting
Code:
10: error: expected primary-expression before ‚while‚
13: error: ‚((((unsigned int)row) & 1u) == 0u)‚ cannot be used as a function
13: error: expected `)' before ‚;‚ token
15: error: expected `;' before ‚)‚ token
17: error: expected primary-expression before ‚else‚
17: error: expected `;' before ‚else‚
EDIT:
For some reason its not coming out as I want it to look on here, its;
17 "-"
5 "|"
9 rows
17 columns

Last edited by carlosk711; 10-08-2012 at 03:32 PM.
 
Old 10-08-2012, 03:42 PM   #2
suicidaleggroll
Senior Member
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 2,987

Rep: Reputation: 1045Reputation: 1045Reputation: 1045Reputation: 1045Reputation: 1045Reputation: 1045Reputation: 1045Reputation: 1045
You really need to work on the formatting/indenting, that code is almost unreadable. It's also full of unbalanced parenthesis...at least I think, I can't tell because of the formatting. You have an else if inside a while, etc.

Last edited by suicidaleggroll; 10-08-2012 at 03:45 PM.
 
1 members found this post helpful.
Old 10-08-2012, 03:47 PM   #3
carlosk711
Member
 
Registered: Sep 2012
Posts: 52

Original Poster
Rep: Reputation: Disabled
sorry here

Code:
#include <iostream>
using namespace std;
int main()
{

    int row, column;
    row == 0;
    column == 0;
    {if (((row % 2) == 0)

        (while ((row <= 9)
            
            {while ((column <= 17);
            cout << "-";
            column ++)}));
            row ++ ;

    cout << endl) ;

    else if ((row <= 9)
    
        while ((column <= 17)
        {cout << "|   " ;
        column = column + 4));

    row ++;}

    return 0;
}}
I just tried to condense it, hopefully this is better
 
Old 10-08-2012, 03:53 PM   #4
suicidaleggroll
Senior Member
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 2,987

Rep: Reputation: 1045Reputation: 1045Reputation: 1045Reputation: 1045Reputation: 1045Reputation: 1045Reputation: 1045Reputation: 1045
What about this? I completely rewrote the code, I couldn't really figure out what you were trying to do in the example.

Code:
#include <iostream>
using namespace std;

int main()
{
   int row, column;
   for (row=0;row<9;row++)
   {
      for (column=0;column<16;column++)
      {
         if ((row % 2) == 0)
         {
            cout << "-";
         } else {
            if ((column % 5) == 0)
            {
               cout << "|";
            } else {
               cout << " ";
            }
         }
      }  
      cout << endl;
   }
   return 0;
}
 
1 members found this post helpful.
Old 10-08-2012, 04:14 PM   #5
carlosk711
Member
 
Registered: Sep 2012
Posts: 52

Original Poster
Rep: Reputation: Disabled
I like the idea of the for loop, why does it seem easier with the for instead of the while??
 
Old 10-08-2012, 04:17 PM   #6
carlosk711
Member
 
Registered: Sep 2012
Posts: 52

Original Poster
Rep: Reputation: Disabled
ok when i did yours I got,

----------------| | | | ----------------| | | | ----------------| | | | ----------------| | | | ----------------

I there should be an "endl" after each one where should I put them?
 
Old 10-08-2012, 04:41 PM   #7
suicidaleggroll
Senior Member
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 2,987

Rep: Reputation: 1045Reputation: 1045Reputation: 1045Reputation: 1045Reputation: 1045Reputation: 1045Reputation: 1045Reputation: 1045
Did you miss the "cout << endl" line in the code? It looks fine on mine:
Code:
$ g++ test.c 
$ ./a.out 
----------------
|    |    |    |
----------------
|    |    |    |
----------------
|    |    |    |
----------------
|    |    |    |
----------------
 
1 members found this post helpful.
  


Reply

Tags
c++, loops, programming


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Hackety Hack: Toolkit to Make Learn the Ruby Programming Language Really Easy and Fun LXer Syndicated Linux News 0 03-11-2012 01:30 PM
LXer: Hackerspace Global Grid to make an Uncensorable internet in space? LXer Syndicated Linux News 0 01-10-2012 05:41 PM
LXer: Four multimedia plugins make WordPress more fun LXer Syndicated Linux News 0 05-05-2008 12:42 PM
Is there a way to make KDE keep icons allway's aligned to grid? Starch Linux - Newbie 2 01-29-2005 11:02 PM
X11 fun - need to make choices.... Laserjock Linux - Software 7 12-11-2004 03:55 PM


All times are GMT -5. The time now is 01:53 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration