i'm trying to fix this error :

  • (2 Pages)
  • +
  • 1
  • 2

29 Replies - 3255 Views - Last Post: 26 November 2012 - 12:49 AM Rate Topic: -----

#1 jossef  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 15
  • Joined: 23-November 12

i'm trying to fix this error :

Posted 23 November 2012 - 07:30 PM

<stdio.h>
<cs50.h>

int main (void)
{
    int hashes, spaces, heigh
    
    heigh = GetInt () 
    
    do
    {
      printf("please choose a positive integer for the height of Mario's pyramid less then  24:"\n");  
    }  
      while (heigh <= 23);
          
          heigh = GetInt ()
          
          for (int sapces = heigh- 1 ; spaces++);
    {  
          for (int hashes = 0; hashes < d% ; hashes+);
          {
            if(hashes < d%-spaces);
           
            printf("#");
           }
      else {
             printf ("please choose a number between 1 and 23\n");
            }
     }     
}



i'm trying to do half pyramid at the right side
of the screen :S i'm really get tired

This post has been edited by no2pencil: 23 November 2012 - 07:35 PM
Reason for edit:: Added Code Tags


Is This A Good Question/Topic? 0
  • +

Replies To: i'm trying to fix this error :

#2 Adak  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 331
  • View blog
  • Posts: 1,168
  • Joined: 01-April 11

Re: i'm trying to fix this error :

Posted 23 November 2012 - 08:00 PM

Your problem deals with rows and columns, so your solution is best solved in that way:

With one for loop for the rows and it's counter - and one more nested inside for loop, dealing with the chars that you will print on that one row. (in other words, the columns of that row).

Say row one - what do you print? Width of the longest row minus the row number (+1) = the number of spaces, and if all your rows need a at least one #, then you might find it very natural to start your row counting with one, instead of the normal zero we use in C.

Give that a try, and work with the problem using pen and paper to begin recognizing the pattern of logic you'll use. Go through it a few times and you'll begin to recognize the pattern that will make up the backbone of your program.

Practice may not make perfect, but it definitely will sharpen your problem-solving skills.
Was This Post Helpful? 1
  • +
  • -

#3 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: i'm trying to fix this error :

Posted 23 November 2012 - 11:05 PM

Looking at your code, I see that your syntax is wrong in many parts of the program.

1.You seem to be missing ';' in too many places. Eg.lines 6, 8 and 16

2. for (int sapces = heigh- 1 ; spaces++); -> note the spellings,also, your condition for the for loop is missing and semicolon should not be placed at the end of the for loop.

3.for (int hashes = 0; hashes < d% ; hashes+);

Three mistakes here...a)Never use a semicolon after a for loop and b)What exactly did you try to mean by using d%...c)hashes++ should replace hashes+

4.You have used a semicolon after the if statement. You need to remove that and of course...the problem with d%

regards,
Raghav
Was This Post Helpful? 1
  • +
  • -

#4 jossef  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 15
  • Joined: 23-November 12

Re: i'm trying to fix this error :

Posted 23 November 2012 - 11:08 PM

i'm thinking about :
hash= height + 1
space=height - 1
so if the height = 1 (and that's the smaller number ); so 1+1=2hash
space=1-1=0space
if height=23
hash = 24
space=22
i dunno if that's good or no :S
Was This Post Helpful? 0
  • +
  • -

#5 jossef  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 15
  • Joined: 23-November 12

Re: i'm trying to fix this error :

Posted 24 November 2012 - 01:11 AM

#include <stdio.h>
#include <cs50.h>

int main ()
{
    int hash, space, height;
      
     {
      printf("please choose a positive integer for the height of Mario's pyramid less then 24 \n");  
         
    }  
    {
     for ( height=<23 ; height=>1);
               height = GetInt ();      
     }
     for (int sapce = height-1 ; space >= 0; space--)
     {            printf(" ");                 }      

     for (int hash = height+1 ; hash >= 2 ; hash++)
     {               printf(" # ");                     }
              
}


i did my best and i still have an error with that:for ( height=<23 ; height=>1);

MOD EDIT: Added code tags. When posting code...USE CODE TAGS!!!

:code:

This post has been edited by JackOfAllTrades: 24 November 2012 - 04:26 AM

Was This Post Helpful? 0
  • +
  • -

#6 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: i'm trying to fix this error :

Posted 24 November 2012 - 01:15 AM

Remove the semicolon after the for loop and check. Also check for spelling of 'space' in your for loop.

regards,
Raghav
Was This Post Helpful? 1
  • +
  • -

#7 jossef  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 15
  • Joined: 23-November 12

Re: i'm trying to fix this error :

Posted 24 November 2012 - 01:18 AM

still 2 errors :S
Was This Post Helpful? 0
  • +
  • -

#8 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: i'm trying to fix this error :

Posted 24 November 2012 - 01:19 AM

Can you post the exact errors?

regards,
Raghav
Was This Post Helpful? 1
  • +
  • -

#9 jossef  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 15
  • Joined: 23-November 12

Re: i'm trying to fix this error :

Posted 24 November 2012 - 01:21 AM

( height=<23 ; height=>1);

mario2.c:13:19: error: expected expression
for ( height=<23 ; height=>1)
^
mario2.c:13:32: error: expected expression
for ( height=<23 ; height=>1)
Was This Post Helpful? 0
  • +
  • -

#10 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: i'm trying to fix this error :

Posted 24 November 2012 - 01:22 AM

Well, the for loop is supposed to be like this.

for(initialization; loop condition; increment/decrement)
{
//code
}


Also you should make it height<= and not height=<

regards,
Raghav

This post has been edited by raghav.naganathan: 24 November 2012 - 01:23 AM

Was This Post Helpful? 0
  • +
  • -

#11 jossef  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 15
  • Joined: 23-November 12

Re: i'm trying to fix this error :

Posted 24 November 2012 - 01:27 AM

did u mind if u give me an example for for loop?!
Was This Post Helpful? 0
  • +
  • -

#12 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: i'm trying to fix this error :

Posted 24 November 2012 - 01:29 AM

Not at all, here...

for(int i=0;i<10;i++)
{
  printf("*");
}


The above for loop will print 10 stars.

regards,
Raghav

This post has been edited by raghav.naganathan: 24 November 2012 - 01:29 AM

Was This Post Helpful? 1
  • +
  • -

#13 jossef  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 15
  • Joined: 23-November 12

Re: i'm trying to fix this error :

Posted 24 November 2012 - 01:39 AM

( )
mario2.c:13:32: note: use '==' to turn this assignment into an equality comparison
for ( height<= 23 ; height= 1 ; height++)
^
==
mario2.c:13:18: warning: expression result unused [-Wunused-value]
for ( height<= 23 ; height= 1 ; height++)
~~~~~~^ ~~
2 warnings generated.
/tmp/mario2-ajN9tx.o: In function `main':
mario2.c:(.text+0x35): undefined reference to `GetInt'
clang: error: linker command failed with exit code 1 (use -v to see invocation) [err_drv_command_failed]

i'm really too tired of that ..... it's my first code i'm working on this little code for more than 4 days!! :S
Was This Post Helpful? 0
  • +
  • -

#14 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: i'm trying to fix this error :

Posted 24 November 2012 - 01:40 AM

Good effort, but not like that...you need to do the initialization first.
for(height=1;height<=23;height++)


Also, I don't see your getInt function defined at all...where is your getInt() function?

{
printf("please choose a positive integer for the height of Mario's pyramid less then 24 \n");

}


I'm guessing you need to make the above code your getInt() function.

Thirdly, you should allow your main to exit by providing a return 0.

regards,
Raghav

This post has been edited by raghav.naganathan: 24 November 2012 - 01:44 AM

Was This Post Helpful? 1
  • +
  • -

#15 jossef  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 15
  • Joined: 23-November 12

Re: i'm trying to fix this error :

Posted 24 November 2012 - 01:48 AM

did u mind to show me how to do it on my code ?
i will be really appreciated :)/>

#include <stdio.h>
#include <cs50.h>

int main ()
{
    int hash, space, height;
      
     {
      printf("please choose a positive integer for the height of Mario's pyramid less then 24 \n");  
         
    }  
    {
     for ( height=1 ; height<= 23 ; height++)
               height = GetInt ();      
     }
     for ( space = height-1 ; space >= 0; space--)
     {            printf(" ");                 }      

     for ( hash = height+1 ; hash >= 2 ; hash++)
     {               printf(" # ");                     }
         return 0;     
}

This post has been edited by JackOfAllTrades: 24 November 2012 - 04:27 AM
Reason for edit:: Added code tags

Was This Post Helpful? -1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2