我已经在网上找遍了,不知道指导是什么意思,而且他不喜欢在4-5天后才回复。非常快速和简短的项目概述:-Create三个文件在Putty Unix中,(main.cpp -由讲师提供,functions.cpp,函数。h) -Purpose:计算用户输入的2个整数的平均值,列出GCM,列出LCM
我很可能对GCM和LCM没什么意见,但我坚持的是一般的部分。在main中取消对doAverage()调用的注释的指令。不过,在他提供的main.cpp中没有doAverage(),我尝试删除了case 3下的doAverage,但程序仍然不能工作。我是不是遗漏了什么?
main.cpp代码:
#include <iostream>
#include "functions.h"
using namespace std;
void getValues(int& x,int& y) {
cout << "Enter the first integer: ";
cin >> x;
cout << "Enter the second integer: ";
cin >> y;
}
int main() {
int choice;
bool done = false;
int x,y;
cout << "Welcome to the math functionator!" << endl << endl;
do {
cout << "1) GCD" << endl;
cout << "2) LCM" << endl;
cout << "3) average" << endl;
cout << "0) quit" << endl;
cout << "Enter choice: ";
cin >> choice;
if (choice != 0) {
getValues(x,y);
}
switch (choice) {
case 1:
//doGCD(x,y);
break;
case 2:
//doLCM(x,y);
break;
case 3:
case 0:
done = true;
}
} while (!done);
cout << "Bye" << endl;
return(0);
}functions.cpp代码:
#include <iostream>
using namespace std;
void doAverage(int x, int y);
{
int sum = x+y;
int average = sum/2;
cout << "Average of " << x << " and " << y << " is " << average << endl;
}functions.h代码:
void doAverage(int x, int y);main.cpp由教师提供,来自functions.cpp的代码以及functions.h也由教师提供。说明说要从main中取消对doAverage的注释,但我认为只有在有#或./等的情况下才会取消注释。
发布于 2016-05-14 04:58:13
我认为您所提供的main.cpp中存在一个小错误。案例3应该是这样的:
case 3:
//doAverage(x,y);
break;注释掉一段代码就是用/* ... */包围它,或者在它前面加上//。要取消注释,就是删除注释标记。在上面提供的代码中,对doAverage的调用被注释掉了。您需要删除注释字符。
此外,用this问题的答案敲打你的讲师的头,告诉他不要再用using namespace std;误导你
https://stackoverflow.com/questions/37218770
复制相似问题