// Write a function named print_out that prints all the whole numbers from 1 to N.
// by calling a function.
#include "stdafx.h"
#include <iostream>
using namespace std;
// Function must be declared before being used.
void::print_out(int n);
int main() {
int n;
cout << "Enter a number and press ENTER: ";
cin >> n;
print_out(n);
cout << endl;
return 0;
}
// Print-out function.
// Prints numbers from 1 to n.
int print_out(n) {
int i;
for (i = 1; i <= n; i++) // For i = 1 to n,
cout << i << " "; // print i
return n;
}
以下是錯誤:我宣佈N的功能,但它給我n是undentified錯誤後,我編寫的代碼,並嘗試運行
Error 1 error C2039: 'print_out' : is not a member of '`global namespace''
Error 2 error C2065: 'n' : undeclared identifier
Error 3 error C2448: 'print_out' : function-style initializer appears to be a function definition
4 IntelliSense: identifier "n" is undefined
5 IntelliSense: identifier "n" is undefined
它應該是'INT print_out(INT N)',參數和在主可變是兩個獨立的實體。 – Borgleader
它給我錯誤:不能重載由返回類型單獨區分的函數。當我放入for循環時。 – zezhawk22