参数太少,无法C++发挥作用
too few arguments to function C++
#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 个函数的参数太少了。任何帮助将不胜感激!对我来说,看起来所有的论点都是有效的,但我只是一个初学者。
在这里,你声明了一个需要三个参数的函数:
void intMathOperations(int rows, int b, int width);
在这里,您完全没有参数地调用它:
intMathOperations();
编译器告诉您这是不正确的。writeHeaderLine
和writeMathLine
相同。
您正在调用这些没有参数的函数
void intMathOperations(int rows, int b, int width);
void writeHeaderLine(int width);
void writeMathLine(int a, int b, int width);
相关文章:
- 我的神经网络不起作用 [XOR 问题]
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- 未在作用域中声明unordered_map
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- C++为什么尽管我调用了void函数,它却不起作用
- 为什么在保护模式下继承升级不起作用
- 循环在计数器中不起作用
- 有没有一种方法可以在编译时获得作用域类名
- 在其他文件中创建类时在 c++ 项目中不起作用
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- 为什么二进制搜索在我的测试中不起作用
- C++quit()函数中可能存在作用域问题
- 我的代码中有错误吗?使用BGI图形的C++代码对我不起作用
- 为什么 const std::p air<K,V>& 在 std::map 上基于范围的 for 循环不起作用?
- 带有指定长度字符* 参数的 std::regex_search 在 VS2017 中不起作用?
- "using namespace std;"在C++的作用是什么?
- Bjarne Stroustrup Book - std_lib_facilities.h - 不起作用(未知类型名称)
- 为什么简单的算术减法在"if"条件下不起作用?
- 为什么Stroustup书中的has_f不起作用
- 未在此作用域OpenCV3.4中声明cvSaveImage