gpt4 book ai didi

c++ - 编译三个文件以创建平均程序(取消注释?)

转载 作者:行者123 更新时间:2023-11-30 03:41:43 25 4
gpt4 key购买 nike

我一直在网上看,不知道导师是什么意思,他不喜欢4-5天后才回复。非常快速和简要的项目概述:- 在Putty Unix中创建三个文件,(main.cpp - 导师提供,functions.cpp,functions.h)- 用途:计算用户输入的2个整数的平均值,列出GCM,列出LCM

我很可能对 GCM 和 LCM 没意见,但平均水平是我坚持的部分。说明取消注释 main 中对 doAverage() 的调用。尽管他提供的 main.cpp 中没有 doAverage(),我已经尝试删除情况 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);
}

函数.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;
}

函数.h代码:

void doAverage(int x, int y);

main.cpp是导师提供的,functions.cpp和functions.h的代码也是导师提供的。说明说要从 main 中取消注释 doAverage,但我认为你只有在有 # 或 ./等时才取消注释...

最佳答案

我认为提供给您的 main.cpp 中存在一个小错误。案例 3 应该是这样的:

        case 3:
//doAverage(x,y);
break;

注释一段代码就是用/* ... */包围它或者在它前面加上//。取消注释,就是删除注释标记。在上面提供的代码中,对 doAverage 的调用被注释掉了。您需要删除注释字符。

此外,用 this 的答案打败你的导师问题,并告诉他不要用 using namespace std;

误导你

关于c++ - 编译三个文件以创建平均程序(取消注释?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37218770/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com