This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center
                            
                        
                    
                
                                7年前关闭。
            
                    
#include <iostream>
#include <iomanip>
using namespace std;

int calculate ()
{
double a;
double b;
a =(3.0);
b =(5.0);
cout << "  " << fixed << setprecision (1) << a << "\n" << endl;
cout << "* " << fixed << setprecision (1) << b << "\n" << endl;
cout << "------" << endl;
cout << fixed << setprecision (2) << a*b << "\n" << endl;
system("PAUSE");

return 0;
}
int calculate(int a, int b, int c)
{
double a;
double b;
double c;
a =(7.1);
b =(8.3);
c =(2.2);
cout << "  " << fixed << setprecision (1) << a << "\n" << endl;
cout << "* " << fixed << setprecision (1) << b << "\n" << endl;
cout << "- " << fixed << setprecision (1) << c << "\n" << endl;
cout << "------" << endl;
cout << fixed << setprecision (2) << (a*b)-c << "\n" << endl;
system("PAUSE");

return 0;
}


问题:为什么我必须更改双精度数---> int?有什么突出的地方是错误的吗?

这是输出:
1> ------开始构建:项目:HW1-2,配置:调试Win32 ------
1> HW1-2.cpp
1> c:\ users \ asus \ desktop \ hw1-2 \ hw1-2 \ hw1-2.cpp(21):错误C2082:重新定义形式参数'a'
1> c:\ users \ asus \ desktop \ hw1-2 \ hw1-2 \ hw1-2.cpp(22):错误C2082:重新定义形式参数'b'
1> c:\ users \ asus \ desktop \ hw1-2 \ hw1-2 \ hw1-2.cpp(23):错误C2082:重新定义形式参数'c'
1> c:\ users \ asus \ desktop \ hw1-2 \ hw1-2 \ hw1-2.cpp(24):警告C4244:'=':从'double'转换为'int',可能丢失数据
1> c:\ users \ asus \ desktop \ hw1-2 \ hw1-2 \ hw1-2.cpp(25):警告C4244:'=':从'double'转换为'int',可能丢失数据
1> c:\ users \ asus \ desktop \ hw1-2 \ hw1-2 \ hw1-2.cpp(26):警告C4244:'=':从'double'转换为'int',可能丢失数据
==========构建:0成功,1失败,0最新,跳过0 ==========

最佳答案

您有两个函数均名为main()。我不确定您要完成什么,但是函数在名称空间中必须具有唯一的名称。

您可以随意命名函数。但是,main()是特殊的-它是程序的入口点,程序运行时会被调用。如果还有另一个函数,则要执行该函数,则需要在main()内部自己调用它:

int foo(int c)
{
    return c + 2;
}

int main()
{
    int a = 1;
    int b = foo(a);
    return b;
}

关于c++ - 简单计算器程序有什么问题? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12470615/

10-10 17:58