C++

Discussion in 'Programming' started by ApoorvKhatreja, Aug 30, 2006.

Thread Status:
Not open for further replies.
  1. ApoorvKhatreja

    ApoorvKhatreja New Member

    Joined:
    Aug 15, 2006
    Messages:
    229
    Likes Received:
    1
    Trophy Points:
    0
    Location:
    Delhi
    ahem....... i may seem very foolish, but could somebody help me out with a c++ program?


    i have to write a program which produces the following output -
    *
    * *
    * *
    * *
    * *
    ************
    (this is actually the border of an equilateral triangle....i dunno why it appears like this over here........i tried to edit it a hundered times......but its coming that way)


    and i have to do this using a loop ..........
    it's a school assignment and i really need help!!!


    its a triangle, empty from inside, and the border has been created by asterisks (*).
     
    Last edited: Aug 31, 2006
  2. mod-the-pc

    mod-the-pc Back to School Mr. Bean !

    Joined:
    Apr 1, 2004
    Messages:
    344
    Likes Received:
    5
    Trophy Points:
    18
    Location:
    Chennai
    for(i=0;i<10;i++)
    for(j=0;j<10;j++)
    {
    if(i==j) //The slope of the triangle
    cout<<"*\n";
    else if(j==0 && i!=0) //The height of the tirangle
    cout<<"*";
    else if (i==9) //The base of the triangle
    cout<<"*";
    else if(j<i)//Empty fill inside the triangle
    cout<<" ";
    }


    I don't have a C/C++ compiler. However let me know if this works.
     
  3. OP
    OP
    ApoorvKhatreja

    ApoorvKhatreja New Member

    Joined:
    Aug 15, 2006
    Messages:
    229
    Likes Received:
    1
    Trophy Points:
    0
    Location:
    Delhi
    its an EQUILATERAL TRIANGLE!!!!!! not a right angled triangle!!!!!
     
  4. Official Techie

    Official Techie New Member

    Joined:
    Jan 25, 2005
    Messages:
    439
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Somewhere in motherboard
    #include<fstream.h>
    #include<conio.h>

    void main()
    {
    ofstream filout;
    filout.open("marks.dat", ios::eek:ut);
    char ans = 'y';
    int rollno;
    float marks;

    while(ans =='y'||ans =='Y')
    {
    cout<<"\n Enter roll no:";
    cin>>rollno;
    cout<<"want to enter more";
    cin>>ans;
    }
    filout.close;
    }







    my problem the file marks.dat should store all the values i enter but its no doing so how can i mak eit do so it should have been doing so
     
  5. sakumar79

    sakumar79 Active Member

    Joined:
    Nov 28, 2004
    Messages:
    2,441
    Likes Received:
    9
    Trophy Points:
    38
    Location:
    Madurai
    You are using cout which will output to screen. You should be sending output to filout perhaps by using put function, etc.

    Arun
     
Thread Status:
Not open for further replies.

Share This Page