-
February 17th, 2012, 02:09 AM
#1
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=1; i<=n; i++)
print_out(i);
system ("pause");
return 0;
}
void print_out ( int x ) {
cout <<x;
}
-
February 17th, 2012, 05:45 AM
#2
Re: Write a print function
 Originally Posted by jacksparrow
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
-
February 17th, 2012, 09:31 AM
#3
Re: Write a print function
[ Moved thread ]
@jacksparrow
Please, post console programming problems (like this one) in C++ (Non Visual C++ Issues) forum.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|