4 Replies - 679 Views - Last Post: 30 March 2013 - 06:34 AM Rate Topic: -----

#1 princeola  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 30-March 13

I need to achieve this task urgently

Posted 30 March 2013 - 12:43 AM

Hi,
please I have been trying to write a code in C to prompt for # input, to create a height of 8 steps of pyramid in horizontal shapes. This is what I have tried on doing:
# include <stdio.h>
# include <math.h> 

   int main (int argc, char* argv[])
{
    int iterations = GetInt();
    
    if (iterations == 8)
    {
        printf("iterations is 8 :)/>\n");
    }
    else
    {
        printf("iterations is not 8 :)/>\n);
        
    for(int i = 0; i > iterations; i++)
    {
        printf("%d\n");
    }
    
    int i = 8;
    
    iterations=9;
    
    while (i => iterations)
    
    {
        printf("%d\n");
        
        i++;
    
        i = i + 1;
    
        i += 1;
    
    } 
}

I want to achieve something like this:
#
##
###
####
#####
######
#######
########


Please help me out, thanks

This post has been edited by Salem_c: 30 March 2013 - 01:45 AM
Reason for edit:: fixed the tags


Is This A Good Question/Topic? 0
  • +

Replies To: I need to achieve this task urgently

#2 Salem_c  Icon User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 2130
  • View blog
  • Posts: 4,196
  • Joined: 30-May 10

Re: I need to achieve this task urgently

Posted 30 March 2013 - 02:06 AM

Start with better variable names - ones which actually mean something.

Say
for ( r = 0 ; r < numberOfRows ; r++ ) {
  int numberOfHashesOnThisRow = 0;  // can you figure out what value to use?
  for ( h = 0 ; h < numberOfHashesOnThisRow ; h++ ) {
  }
}


Was This Post Helpful? 0
  • +
  • -

#3 princeola  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 30-March 13

Re: I need to achieve this task urgently

Posted 30 March 2013 - 05:10 AM

View Postprinceola, on 30 March 2013 - 12:43 AM, said:

Hi,
please I have been trying to write a code in C to prompt for # input, to create a height of 8 steps of pyramid in horizontal shapes. This is what I have tried on doing:
# include <stdio.h>
# include <math.h> 

   int main (int argc, char* argv[])
{
    int iterations = GetInt();
    
    if (iterations == 8)
    {
        printf("iterations is 8 :)/>/>\n");
    }
    else
    {
        printf("iterations is not 8 :)/>/>\n);
        
    for(int i = 0; i > iterations; i++)
    {
        printf("%d\n");
    }
    
    int i = 8;
    
    iterations=9;
    
    while (i => iterations)
    
    {
        printf("%d\n");
        
        i++;
    
        i = i + 1;
    
        i += 1;
    
    } 
}

I want to achieve something like this:
#
##
###
####
#####
######
#######
########


Please help me out, thanks


Hi Salem_c,

I did what you said , but am getting all this errors please help me out where am wrong:

(~/Dropbox/hashes): make hashes
clang -ggdb3 -O0 -std=c99 -Wall -Werror hashes.c -lcs50 -lm -o hashes
hashes.c:13:11: error: use of undeclared identifier 'r'
for ( r = 0 ; r < number of Rows ; r++ )
^
hashes.c:13:19: error: use of undeclared identifier 'r'
for ( r = 0 ; r < number of Rows ; r++ )
^
hashes.c:13:23: error: use of undeclared identifier 'number'
for ( r = 0 ; r < number of Rows ; r++ )
^
hashes.c:13:40: error: use of undeclared identifier 'r'
for ( r = 0 ; r < number of Rows ; r++ )
^
hashes.c:15:7: error: expected expression
int = 1; r < 8;
^
hashes.c:15:16: error: use of undeclared identifier 'r'
int = 1; r < 8;
^
hashes.c:19:14: error: expected ';' at end of declaration
int number of Hashes on This Row = ;
^
;
hashes.c:23:8: error: use of undeclared identifier 'h'
for ( h = 0 ; h < number of Hashes on This ...
^
hashes.c:23:16: error: use of undeclared identifier 'h'
for ( h = 0 ; h < number of Hashes on This ...
^
hashes.c:23:51: error: use of undeclared identifier 'h'
...( h = 0 ; h < number of Hashes on This Row ; h++ )
^
hashes.c:25:4: error: expected expression
int = 1; r < 2; 1++;
^
hashes.c:25:13: error: use of undeclared identifier 'r'
int = 1; r < 2; 1++;
^
hashes.c:25:21: error: expression is not assignable
int = 1; r < 2; 1++;
~^
hashes.c:31:2: error: expected '}'
}
^
hashes.c:9:1: note: to match this '{'
{
^
14 errors generated.
make: *** [hashes] Error 1
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • say what now
  • member icon

Reputation: 6409
  • View blog
  • Posts: 25,903
  • Joined: 12-December 12

Re: I need to achieve this task urgently

Posted 30 March 2013 - 05:20 AM

Quote

error: use of undeclared identifier 'r'
for ( r = 0 ; r < number of Rows ; r++ )

That error is very clear: you haven't declared r.

Why have you inserted all those spaces? Variable-names cannot contain any spaces.

This knowledge is fundamental to any programming language, so I think you need to start-over. There are tutorials here at DIC.
Was This Post Helpful? 0
  • +
  • -

#5 Salem_c  Icon User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 2130
  • View blog
  • Posts: 4,196
  • Joined: 30-May 10

Re: I need to achieve this task urgently

Posted 30 March 2013 - 06:34 AM

> I did what you said , but am getting all this errors please help me out where am wrong:
You blindly copy and pasted, without exercising any thought about what was going on.

It's a clue, something to make you think!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1