CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  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,449

    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
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: Write a print function

    [ Moved thread ]

    @jacksparrow
    Please, post console programming problems (like this one) in C++ (Non Visual C++ Issues) forum.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

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
  •  





Click Here to Expand Forum to Full Width

Featured