#include<cstdlib> //Required for compatibility
#include<cmath> //Required for pow
#include<fstream> //Required for data files
#include<iostream> //Required for cout and cin
#include<iomanip> //Required for setw
using namespace std;
int choice, loops, count;
double initTime, timeIncrement, finalTime, time, A1, B1, C1, D1, E1,
altitude, A2, B2, C2, D2, E2, velocity; //This is line 20 as the error notes
//Declare variables
ifstream inFile;
ofstream outFile;
void menuFunction() {
//Main menu function where user selects which option they would like to proceed with, not relevant to question
}
double altitudeFunction(double& altitude) {
//Altitude calculation
altitude = A1 * pow(time, 4.0) + B1 * pow(time, 3.0) + C1 * pow(time, 2.0) + D1 * time + E1; //This is line 36 as the error notes
}
double velocityFunction(double& velocity) {
//Velocity calculation
velocity = A2 * pow(time, 4.0) + B2 * pow(time, 3.0) + C2 * pow(time, 2.0) + D1 * time + E1; // This is line 41, as the error notes
}
void parameters() {
//Function to enter time parameters to save space, not relevant to errors
}
int main() {
menuFunction();
while (choice != 4) {
switch (choice) {
case 1: {
parameters();
if (finalTime < 5 || finalTime > 24) {
//Required invalid entry error message
//Redisplay menu to allow user another try
}
else {
//Open input file for option 1
//Find variables in input file
//close input file and open output file
//Make output file look neat
//Column headers for output file for readability
loops = (int)((finalTime - initTime) / timeIncrement);
for (count = 0; count <= loops; count++) { //For loop for incremental calculations, this is line 86 as the error notes
time = initTime + count * timeIncrement;
//Run both calculation functions
//Print results to output file during for loop
}
//close output file
system("CLS");
//Print message to screen saying data was recorded to output file
}
break;
}
case 2: {
parameters();
if (finalTime < 5 || finalTime > 24) {
//Required invalid entry error message
//Redisplay menu to allow user another try
}
else {
//Open input file for option 1
//Find variables in input file
//close input file and open output file
//Make output file look neat
//Column headers for output file for readability
loops = (int)((finalTime - initTime) / timeIncrement);
for (count = 0; count <= loops; count++) { //For loop for incremental calculations, this is line 118 as the error notes
time = initTime + count * timeIncrement;
//Run both calculation functions
//Print results to output file during for loop
}
//close output file
system("CLS");
//Print message to screen saying data was recorded to output file
}
break;
}
case 3: {
parameters();
if (finalTime < 5 || finalTime > 24) {
//Required invalid entry error message
//Redisplay menu to allow user another try
}
else {
//Open input file for option 1
//Find variables in input file
//close input file and open output file
//Make output file look neat
//Column headers for output file for readability
loops = (int)((finalTime - initTime) / timeIncrement);
for (count = 0; count <= loops; count++) { //For loop for incremental calculations, this is line 150 as the error notes
time = initTime + count * timeIncrement;
//Run both calculation functions
//Print results to output file during for loop
}
//close output file
system("CLS");
//Print message to screen saying data was recorded to output file
}
break;
}
default: {
cout << "\tInvalid Entry!\n\n"; //Error message if user enters an invalid menu option
menuFunction();
}
}
}
if (choice == 4) {
//end program
system("pause");
return 0;
}
}
在我的第一个学期的C ++编码中,我不明白为什么但是由于某些原因,当我运行这个确切的程序时,它在Dev C ++中编译得很好,但我在Visual Studio 2017中遇到了许多错误。我试图复制并粘贴错误,但它没有正确格式化,所以基本上每个“时间”和“计数”的实例都给我一个错误,说“'时间/计数'是不明确的”以及以下不太常见的错误:
错误C2659'=':作为左操作数86,118,150
运行错误C2365'时间':重新定义:之前的定义是 '功能'20
错误C2297'*':非法,右操作数的类型为'time_t(__ cdecl *)(time_t * const)'36,41
错误C2665'pow':6个重载中没有一个可以转换所有 参数类型36,41
该程序应该从输入文件中提取气象气球数据输入,做一些数学运算以在特定时间获得高度和速度值,并将这些值输出到新的数据文件。它在Dev C ++上编译,运行和完美运行,但不能在Visual Studio上编译。我只是问,因为我提交了这个课程,因为它没有在教授的计算机上编译,所以给了0,但我的工作正常。有什么想法吗?
编辑删除我的名字以及代码的非相关部分。
中保留了代码中的注释所取代的所有内容,包含错误的代码部分。答案 0 :(得分:10)
这可能表明using namespace std;
是个坏主意的一个原因。
标准库包含std::time
函数,该函数由using
引入。
现在编译器不知道普通time
是否意味着在此程序中声明的::time
变量或std::time
函数。
可能在某些系统上编译的原因是允许C ++标准头部间接包含任何其他标准头。因此,偶然使用Dev-C ++的标准库头文件可能不包括std::time
。