Excercise:
Write a function named print_out that prints all the whole numbers from 1 to n. Test the function by placing it in a program that passes a number n to it, 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.
-----
The chapter is about functions and i believe the purpose is just to use void.
i am using visual c++
i am getting these errors.
error C2065: 'n' : undeclared identifier
error C2448: 'print_out' : function-style initializer appears to be a function definition
here is what i have so far
p.s. please forgive the sloppy post i mostly just read the forums and dont post much
#include <stdafx.h>
#include <iostream>
using namespace std;
void print_out(int n);
int main() {
int n;
cout << "Enter a number and press ENTER: ";
cin >> n;
print_out(n);
return 0;
}
int print_out(n) {
int i;
for (i = 1; i <= n; i++)
cout << i << " ";
return sum;
}
some of this code was copied from the book but i believe it is correct syntax


Sign In
Create Account

Back to top









