Thread: making a diamond using functions

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    31

    Unhappy making a diamond using functions

    i have this other question regarding functions. well firstly i have to write this program..the output has to be a diamond shape...the user has to input the number of rows n the character the diamond will be composed of.
    it should incorporate the following functions:
    Code:
    int PromtNRows ( void ) // propmt the user for the number of rows
    void PrintLine ( int n, char ch ( //print n copies of ch on current line
    the output should be a diamond
    can neone help me on this?

  2. #2
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    Do a search and produce some code, then come back if you need help.

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    31
    well i guess its supposed to like this with out functions..but its not working:

    Code:
    # include <iostream>
    
    using namespace std;
    
    int main()
    { 
    	int row, space, num;
    	char ch;
    
    	// Get int and char
    
    	cout << "Enter number of rows: "<< flush;
    	cin  >> num;
    	cout << "Enter a character: "<< flush;
    	cin  >> ch;
    	
    
    	// This is checking if n is odd or even
    	// If even then we add 1 to n to make it odd
    	
    	if (!(num % 2)) 
    	{
    		num++;
    	}
    
    	//This loop is for the upper crest
    
    	space = 0;
    	for (row = 0 ; row <= num ; row++)
    	{
    		
    	
    		for (space = (num /row) -1 ; space < row ; space++)
    		{
    			cout << endl;
    		}
    	
    	}
    
    	//This loop is for the lower crest
    	
    	for (row = num - 1 ; space > 0 ; row--)
    	{
    		cout << ch;
    	
    
    		for (space = 0 ; space < row; space++)
    		{
    			cout << endl;
    		}
    	}
    	
    	return 0;
    }
    need some guideance plz

  4. #4
    Registered User
    Join Date
    Mar 2003
    Posts
    31
    well i guess it should be like this..i figured the relationship out but its still not working..
    Code:
    # include <iostream>
    
    using namespace std;
    
    int main()
    { 
    	int row, space, num;
    	char ch;
    
    	// Get int and char
    
    	cout << "Enter number of rows: "<< flush;
    	cin  >> num;
    	cout << "Enter a character: "<< flush;
    	cin  >> ch;
    	
    
    	// This is checking if n is odd or even
    	// If even then we add 1 to n to make it odd
    	
    	if (!(num % 2)) 
    	{
    		num++;
    	}
    
    	//This loop is for the upper crest
    
    	row = 0;
    	for (row = num - 1; row <= num ; row++)
    	{
    		cout << ch;
    	
    		for (space = (num /row) -1 ; space < row ; space++)
    		{
    			cout <<space; 
    		}
    		cout << ' ';
    		cout << endl;
    	}
    
    	//This loop is for the lower crest
    	
    	for (row = num - 1 ; space > 0 ; row--)
    	{
    		cout << ch;
    	
    
    		for (space = 0 ; space < row; space++)
    		{
    			cout << space;
    		}
    	}
    	
    	return 0;
    }

  5. #5
    The Pantless Man CheesyMoo's Avatar
    Join Date
    Jan 2003
    Posts
    262
    Edit----------------------------------------------
    Everything I said in this post was wrong.
    If you ever need a hug, just ask.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Is it legal to have functions within functions?
    By Programmer_P in forum C++ Programming
    Replies: 13
    Last Post: 05-25-2009, 11:21 PM
  2. Making functions
    By Kool4School in forum C Programming
    Replies: 17
    Last Post: 11-16-2008, 09:22 PM
  3. Bitwise Unwanted Output
    By pobri19 in forum C++ Programming
    Replies: 4
    Last Post: 09-15-2008, 04:07 AM
  4. Expression Manipulator v0.2 (bug fixes, functions)
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 05-26-2003, 04:52 PM
  5. trouble defining member functions
    By dP munky in forum C++ Programming
    Replies: 7
    Last Post: 04-13-2003, 08:52 PM