Write a print function
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Write a print function

  1. #1
    Join Date
    Jul 2010
    Posts
    75

    Arrow Write a print function

    Hi
    i did write a print function which the user put a number and then it will print out till that number

    the output is correct ,, but is code correct ? or it could be better somehow ?

    write a function named print_out that print all the whole numbers from 1 to n. test the function by placing it in a program that passes a number n to print_out , where this number is entered from the keyboard . the print_out function should have type void; it does not return a value. the function can be called with a simple statement:

    print_out(n);


    PHP Code:

    # include <iostream>
    using namespace std;
    void print_out (int x);
    int main () {

        
    int n;

        
    cout << " enter a number : ";
        
    cin >>n;

        for ( 
    int i=1i<=ni++)
            
    print_out(i);

        
    system ("pause");
        return 
    0;
    }

    void print_out int x ) {
        
    cout <<x


  2. #2
    Join Date
    Apr 1999
    Posts
    27,431

    Re: Write a print function

    Quote Originally Posted by jacksparrow View Post
    Hi
    i did write a print function which the user put a number and then it will print out till that number
    No you didn't. You wrote a function that prints one number and then returns.

    All you did was call this function n times. That does not satisfy the requirement of your assignment:
    write a function named print_out that print all the whole numbers from 1 to n.
    The entire function must do this work.

    Regards,

    Paul McKenzie

  3. #3
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,027

    Re: Write a print function

    [ Moved thread ]

    @jacksparrow
    Please, post console programming problems (like this one) in C++ (Non Visual C++ Issues) forum.
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center