带标头文件的C 中的错误
Errors in c++ with header files
你好,我正在尝试使用标头文件运行此代码
//#include <iostream>
//#include <cmath>
#include "formula.h"
//using namespace std;
int main()
{
//double r1;
//double r2;
//double r3;
//double combinedresistors;
//double counter;
cout << "Enter your first resistance value:";
cin >> r1;
cout << "Enter your second resistance value:";
cin >> r2;
cout << "Enter your third resistance value:";
cin >> r3;
//combinedresistors = 1/((1/r1) + (1/r2) + (1/r3));
if (r1 == 0 )
cout << "ERROR:You can't have your resistance(s) value be zero";
// counter = 1;
else if (r2 == 0)
cout << "ERROR:You can't have your resistance(s) value be zero";
// counter = 1;
else if (r3 == 0)
cout << "ERROR:You can't have your resistance(s) value be zero";
// counter = 1;
else
cout << "Your combined Resistance is:" << combinedresistors << endl;
return 0;
}
这是标题文件。它称为公式。h
//header file
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
double combinedresistors;
double r1;
double r2;
double r3;
combinedresistors = 1/((1/r1) + (1/r2) + (1/r3));
我已经评论了main.cpp文件中的零件,因为我认为我不需要它们,因为它们在标头文件中。这是我遇到的错误...
c:work areac++lab3formula.h(15): error C4430: missing type specifier -
int assumed. Note: C++ does not support default-int
c:work areac++lab3formula.h(15): error C2371: 'combinedresistors':
redefinition; different basic types
c:work areac++lab3formula.h(10): note: see declaration of
'combinedresistors'
.Lab3.cpp(34): error C2088: '<<': illegal for class
我尝试了很多事情,并在互联网上浏览了很多东西,但我需要帮助。
谢谢。
您需要在某些功能中编写combinedresistors = 1/((1/r1) + (1/r2) + (1/r3));
。喜欢,
double GetCombinedResistors()
{
return 1/((1/r1) + (1/r2) + (1/r3));
}
使用,
cout << "Your combined Resistance is:" << GetCombinedResistors() << endl;
我不是一个好的CPP程序员,但是您可以尝试以下操作:
//#include <cmath>
#include "formula.h"
//using namespace std;
int main()
{
double r1;
double r2;
double r3;
double combinedresistors;
double counter;
cout << "Enter your first resistance value:";
cin >> r1;
cout << "Enter your second resistance value:";
cin >> r2;
cout << "Enter your third resistance value:";
cin >> r3;
if (r1 == 0 || r2 == 0 || r3 == 0){
cout << "ERROR:You can't have your resistance(s) value be zero";
}
else{
combinedresistors = 1/((1/r1) + (1/r2) + (1/r3));
cout << "Your combined Resistance is:" << combinedresistors << endl;
}
return 0;
}
相关文章:
- 用MacOS Mojave编译C++:致命错误:mpi.h:没有这样的文件或目录
- 多个文件的内存分配错误"在抛出 'std :: bad_alloc' what (): std :: bad_alloc 的实例后终止调用" [C++]
- 如何在文件和行号中抛出错误
- 防止在C++中选择错误文件时提升 xml 解析器崩溃
- AMQP-CPP >处理程序中的错误文件描述符
- Xcode OSX上的C++构建失败,出现多个错误文件IO..不可用:在macOS 10.15中引入
- 为什么生成文件返回 g++: 错误: h 文件或目录 make: *** [生成文件:12: 测试] 错误 1?
- 警告:打开错误文件(/build/opencv/modules/videoio/src/cap_ffmpeg_impl.
- Ubuntu C++ 编译器错误: g++: 错误: 文件.cpp: 没有这样的文件或目录
- main.cc:5:30:致命错误:文件夹/file.h:没有这样的文件或目录
- C++ LNK2005"已定义"错误 - 文件引用自身
- C++:模拟餐饮公司计费程序-无法将错误数据输出到错误文件
- 博兰德C++链接器错误c文件包括
- Visual Studio 2015 代码覆盖率错误文件
- 使用system()与Gnuplot进行绘图会导致错误:文件不可读
- 是否存在fseek/ftell可能给出错误文件大小的情况
- g++编译错误.h文件
- c++编译错误:.o文件未找到
- 打开错误文件的错误消息
- Ndk-build输出添加符号错误.文件格式错误