2015-02-09 130 views
-7
#include <iostream> 
#include <iomanip> 
#include <cstdlib> 

// function prototypes 
void intOutput(); 
void floatingPointOutput(); 
void intMathOperations(int rows, int b, int width); 
void writeHeaderLine(int width); 
void writeMathLine(int a, int b, int width); 

using namespace std; 

int main() 
{ 
cout << "\nProject 1: Math and Functions"; 
cout << "\n"; 
cout << "\n"; 
cout << "\nProject 1 Start."; 
cout << "\nZack Cunningham"; 
cout << "\n"; 
cout << "\nInteger Output Demo:"; 
cout << "\n"; 

intOutput(); 
floatingPointOutput(); 
intMathOperations(); 
writeHeaderLine(); 
writeMathLine(); 

cout << "\n"; 
cout << "\nProject 1 End."; 
cout << "\n"; 

const int FIELD_WIDTH = 10; 
intMathOperations(12, 5, FIELD_WIDTH); 

return EXIT_SUCCESS; 
} 

void intMathOperations(int rows, int b, int width){ 
cout << "\n"; 
cout << "\nInteger Math Operations Demo:"; 
cout << "\n"; 
writeHeaderLine(width); 
cout << "\n"; 
for (int a = 0; a < rows; ++a){writeMathLine(a, b, width); 
} 
} 


void writeHeaderLine(int width){ 
cout << "\n"; 
cout << setw(width) << "a"; 
cout << setw(width) << "b"; 
cout << setw(width) << "a * b"; 
cout << setw(width) << "a/b"; 
cout << setw(width)<< "a % b"; 
} 

void writeMathLine(int width){ 
int a; 
cout << setw(width) << a; 
int b; 
int rows; 
for (int a = 0; a < rows; ++a){writeMathLine(a, b, width); 
} 
} 

void floatingPointOutput(){ 
double a = 2000; 
double b = 3; 
double c = a/b; 
cout << "\n" << a << "/" << b << " = "; 
cout << "\n" << c; 

cout << setprecision(10); 
cout << "\n" << setw(20) << c; 
cout << scientific; // scientific notation 
cout << "\n" << setw(20) << c; 
cout << fixed; // standard decimal notation 
cout << "\n" << setw(20)<< c; 
cout << left; // left justify 
cout << "\n" << setw(20) << c; 
cout << right; 

// right justify (default) 
cout << "\n" << setw(20) << c; 
cout << setprecision(6); // return to default 
cout << "\n" << setw(20) << c; 
cout << "\n"; 
} 

// function calls 
void intOutput(){ 
cout << "\nInteger Output Demo:"; 
cout << "\n"; 
int a = 12; 
int b = 12345678; 
cout << "\n....5...10...15...20"; // spacing info 
cout << "\n"; 
cout << "\n" << setw(20) << a; 
cout << "\n" << setw(20) << b; 
cout << "\n"; 
cout << "\n" << setw(4) << a; 
cout << "\n" << setw(4) << b; 
cout << left; // left justified 
cout << "\n"; 
cout << "\n" << setw(20) << a; 
cout << "\n" << setw(20) << b; 
cout << right; // right (default) justified 
cout << "\n"; 
} 

這是我的代碼,當然,它給了我3個錯誤,說我的最後3個函數的參數太少。任何幫助將不勝感激!對我來說,看起來所有參數都是有效的,但我只是一個初學者。功能C++的參數太少

+0

當您在這裏發佈的代碼,標籤不工作。因此,確保您爲每個縮進使用一致的空格數。它確實有助於可讀性。 *還有*,'writeMathLine'聲明和實現簽名不同。很簡單。 – crashmstr 2015-02-09 16:03:11

+0

有什麼論點?你沒有提供任何。 – 2015-02-09 16:03:16

+0

您沒有將任何參數傳遞給這些函數?!? – 2015-02-09 16:03:28

回答

6

在這裏,您聲明需要三個參數的函數:

void intMathOperations(int rows, int b, int width); 

在這裏,你不帶任何參數都叫它:

intMathOperations(); 

編譯器告訴你,這是不正確。與writeHeaderLinewriteMathLine相同。

+1

注意:他還*用聲明中的不同數量的參數定義*。 – crashmstr 2015-02-09 16:03:58

+0

好吧,不是那個,而是'void writeMathLine(int a,int b,int width);'/'void writeMathLine(int width){}'。 – crashmstr 2015-02-09 16:05:26

2

要調用這些功能,而無需PARAMS

void intMathOperations(int rows, int b, int width); 
void writeHeaderLine(int width); 
void writeMathLine(int a, int b, int width); 
+1

我在想這可能是推理,我在尋求幫助,而不是做我的項目。但是,謝謝,我感謝幫助和關心;) – 2015-02-09 16:06:10