LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
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
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
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
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:19 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration