Thread: displaying this program 5 times

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    19

    displaying this program 5 times

    Hi!
    im trying to make a program that will display this 5 times...
    our instructor told us that we will use display(); command as a function...
    i dont even know what that is.... what i did to make it work was to copy paste this 5 times.... but i need to learn this:
    here's what i tried so far:

    Code:
    #include <stdio.h>
    #include <conio.h>
    
    display();
    display();
    display();
    display();
    display();
    
    main()
    {
    display();
    
    clrscr();
    gotoxy (34,12);
    printf ("Adam");
    sleep(1);
    clrscr();
    gotoxy(34,14);
    printf ("Adam");
    sleep(1);
    getchar();
    
    }
    so the output should be to display the name inside the main(red) 5 times

    oh i can see that you can use any words other than display
    Last edited by EdwardElric; 08-08-2007 at 08:54 AM.

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    There is the for loop.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Registered User
    Join Date
    Jul 2007
    Posts
    19
    but i cant use loops yet

  4. #4
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    How about just copying and pasting that text 5 times in a row then ? (definitely not the best way of doing things, though)
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  5. #5
    The larch
    Join Date
    May 2006
    Posts
    3,573
    In this case, may-be you are supposed to write a function called display, and call it 5 times in a row?

    Code:
    void display(void)
    {
        //your code here
    }
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  6. #6
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Even if you don't know loops yet, leaning to use one wouldent be too hard. Can you figure out what this does?
    Code:
    int count;
    for(count=0; count<5; count=count+1)
    { 
          //Stuff in here runs 5 times
    }

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    > what i did to make it work was to copy paste this 5 times
    You prototyped it 5 times, and called it once.

    Try the other way round.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #8
    Registered User
    Join Date
    Jul 2007
    Posts
    19
    Quote Originally Posted by anon View Post
    In this case, may-be you are supposed to write a function called display, and call it 5 times in a row?

    Code:
    void display(void)
    {
        //your code here
    }
    yeah i think this is similar
    Code:
    #include <stdio.h>
    #include <conio.h>
    
    display();
    display();
    display();
    display();
    display();
    
    
    void display(void)
    {
    
    clrscr();
    gotoxy (34,12);
    printf ("Adam");
    sleep(1);
    clrscr();
    gotoxy(34,14);
    printf ("Adam");
    sleep(1);
    getchar();
    }
    this still gives errors
    Last edited by EdwardElric; 08-08-2007 at 10:36 AM.

  9. #9
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    this still gives errors
    Well yeah, considering you don't have a main method. Listen to Salem and try :

    Code:
    int main(void)
    {
            display();
            display();
            display();
            display();
            display();
            return 0;
    }
    Instead of :

    Code:
    display();
    display();
    display();
    display();
    display();
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  10. #10
    Registered User
    Join Date
    Jul 2007
    Posts
    19

    Thumbs up

    thanks for the help!

    just figured out how to do it:
    Code:
    #include <stdio.h>
    #include <conio.h>
    
    void display(void);
    
    int main(void)
    {
    display();
    display();
    display();
    display();
    display();
    }
    
    display();
    {
    clrscr();
    gotoxy (34,12);
    printf ("Adam");
    sleep(1);
    clrscr();
    gotoxy(34,14);
    printf ("Adam");
    sleep(1);
    getchar();
    }

  11. #11
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    function calls aren't really function calls when they're not inside a function. Then, it's just saying "hey there's a function by this name!"
    Last edited by robwhit; 08-08-2007 at 11:36 AM. Reason: you got it figured out.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A simple program about displaying number
    By sundar in forum C Programming
    Replies: 17
    Last Post: 08-08-2008, 10:07 AM
  2. Replies: 2
    Last Post: 12-02-2007, 05:40 AM
  3. Date program starts DOS's date
    By jrahhali in forum C++ Programming
    Replies: 1
    Last Post: 11-24-2003, 05:23 PM
  4. I made a times table program, could i have some pointers?
    By Cwarrior in forum C++ Programming
    Replies: 4
    Last Post: 05-02-2003, 01:21 PM
  5. Replies: 2
    Last Post: 05-10-2002, 04:16 PM