Loading
October 23, 2014, 07:45:28 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Welcome!
 
   Forum Home   Help Search Forum Login Register  
Pages: [1]   Go Down
  Send this topic  |  Print  
Author Topic: how to make a diamond and triangle asterisk using loop?  (Read 6868 times)
mayumi225
Newbie
*
Posts: 5


« on: March 11, 2010, 04:05:32 AM »

pls tell me the code
Logged
Michael Hall
Administrator
Hero Member
*****
Posts: 971



« Reply #1 on: March 11, 2010, 10:14:33 AM »

Can you provide an example of what you are looking for as far as the output?

Mike
Logged
mayumi225
Newbie
*
Posts: 5


« Reply #2 on: March 11, 2010, 10:53:21 PM »

Can you provide an example of what you are looking for as far as the output?

Mike
Input: 5


           *
         ***
        *****
      *******
     ********
      ********       the sides are consist of 5 asterisk
        *****
         ***
           *







                                               

max number is 19.
i can only create the half of the diamond but not the whole diamond how can i make a whole diamond?



  
« Last Edit: March 11, 2010, 11:00:05 PM by mayumi225 » Logged
Michael Hall
Administrator
Hero Member
*****
Posts: 971



« Reply #3 on: March 11, 2010, 11:07:09 PM »

Paste the code in here. If you have half of it, you should be able to ge the other half pretty easily--just undo what you already did. Let's take a look at it, and I'll help you out.

Mike
Logged
Michael Hall
Administrator
Hero Member
*****
Posts: 971



« Reply #4 on: March 11, 2010, 11:43:58 PM »

This seems like a common enough thing that I put up an example page for it.

http://xoax.net/ref/cpp_examples/printdiamond.php

There it is! Enjoy!

Mike
Logged
mayumi225
Newbie
*
Posts: 5


« Reply #5 on: March 12, 2010, 12:09:16 AM »

This seems like a common enough thing that I put up an example page for it.

http://xoax.net/ref/cpp_examples/printdiamond.php

There it is! Enjoy!

Mike
#include <iostream.h>
#include <conio.h>
void main()
{
int n;
cout<<"Enter The Value Of n:";
cin>>n;
for(int i=0;i<n;i++)
{
for(int j=n;j>i;j--)
cout<<" ";
for(int k=0;k<i;k++)
cout<<" *";
cout<<"\n";
}
for(i=n;i>0;i--)
{
for(int j=n;j>i;j--)
cout<<" ";
for(int k=0;k<i;k++)
cout<<" *";
cout<<"\n";
getch();
}
}
Logged
Michael Hall
Administrator
Hero Member
*****
Posts: 971



« Reply #6 on: March 12, 2010, 12:41:50 AM »

That seems to work too. However, it has spaces between the asterisks (different than what you had posted before).

I gather that you are working on VC++ 6.0? I noticed that you use <iostream.h>. That is a little out of date with the current C++ standard, and you can get VC++ 2008 Express for free (2010 soon)--just a suggestion.  Wink

Mike
« Last Edit: March 12, 2010, 01:21:05 AM by Michael Hall » Logged
mayumi225
Newbie
*
Posts: 5


« Reply #7 on: March 12, 2010, 02:51:57 AM »

That seems to work too. However, it has spaces between the asterisks (different than what you had posted before).

I gather that you are working on VC++ 6.0? I noticed that you use <iostream.h>. That is a little out of date with the current C++ standard, and you can get VC++ 2008 Express for free (2010 soon)--just a suggestion.  Wink

Mike
i don't know what version is my turbo c
Logged
b1gb0y2013
Newbie
*
Posts: 24


« Reply #8 on: March 12, 2010, 05:45:27 PM »

actually i was bored so i just plugged in your code, first off alot of stuff didnt work for me so i had to change a bunch... But try putting the getchar(); before the LAST }, it works for me now...
Logged

Current C++ console lesson:
Lesson 34 - Public and Private Members
Michael Hall
Administrator
Hero Member
*****
Posts: 971



« Reply #9 on: March 12, 2010, 05:58:11 PM »

You might have trouble because your compiler is older. That's what I was talking about before. C++ no longer uses <iostream.h>. Instead, it use <iostream> and all of the standard libraries are in the namespace "std." Also, <conio.h> is no longer used.

If you are using Visual C++, you can use "Start Without Debugging" and the console window will stay open. Otherwise, you need to add something like getchar(). We covered that in our video on how to create an executable.

Mike
« Last Edit: March 12, 2010, 05:59:42 PM by Michael Hall » Logged
mayumi225
Newbie
*
Posts: 5


« Reply #10 on: March 13, 2010, 12:58:37 AM »

You might have trouble because your compiler is older. That's what I was talking about before. C++ no longer uses <iostream.h>. Instead, it use <iostream> and all of the standard libraries are in the namespace "std." Also, <conio.h> is no longer used.

If you are using Visual C++, you can use "Start Without Debugging" and the console window will stay open. Otherwise, you need to add something like getchar(). We covered that in our video on how to create an executable.

Mike
where can i download the latest version of turbo c?
Logged
Pages: [1]   Go Up
  Send this topic  |  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!