这个c ++程序缺少什么?打印计算 [英] What is missing in this c++ program? printing calculations
问题描述
#include <iostream>
#include <iomanip>
using namespace std;
int main () // print to console: 3.0*5.0=15.00
{
double a;
double b;
a =(3.0);
b =(5.0);
cout << " " << fixed << setprecision (1) << a << "\n" << endl;
cout << "* " << b << "\n" << endl;
cout << "------" << endl;
cout << fixed << setprecision (2) << a*b << "\n" << endl;
return 0;
}
int calculate (int a, int b, int c) // print to console: (7.1*8.3)-2.2=56.73
{
double a;
double b;
double c;
a = (7.1);
b = (8.3);
c = (2.2);
cout << " " << fixed << setprecision (1) << a << "\n" << endl;
cout << "* " << b << "\n" << endl;
cout << "- " << c << "\n" << endl;
cout << "------" << endl;
cout << setprecision(2) << (a*b)-c << "\n" << endl;
}
int calculation (int a, int b, int c) // print to console: 3.2/(6.1*5.0)=0.10
{
double a;
double b;
double c;
a=(3.2);
b=(6.1);
c=(5.0);
cout << " " << fixed << setprecision (1) << a << "\n" << endl;
cout << " /(6.1*5.0)" << endl; //how can I use variables instead of using quotes?
cout << "------" << endl;
cout << setprecision(2) << a/(b*c) << "\n" << endl;
system("PAUSE");
return 0;
}
我使用了一个重复的布局,我希望垂直打印3个函数小数所有排队。我似乎不能得到打印没有错误,并认为我不明白错误输出足以进行必要的更改。我不知道我是否正确地重新定义变量,或者如果我把他们正确地放在一起(使用{})。
I have used a repetitive layout that I was hoping would print 3 functions vertically so that decimals all line up. I cannot seem it to get to print without errors and think I don't understand the error outputs enough to make necessary changes. I don't know if I am redefining the variables properly or if I am putting them together properly (using {}).
感谢任何人谁可以帮助我得到这个上班。
Thanks to anyone who can help me get this to work.
以下是输出结果:
(7): error C2082: redefinition of formal parameter 'a'
(8): error C2082: redefinition of formal parameter 'b'
(9): warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
(10): warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
(21): error C2082: redefinition of formal parameter 'a'
(22): error C2082: redefinition of formal parameter 'b'
(23): error C2082: redefinition of formal parameter 'c'
(24): warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
(25): warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
(26): warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
(34): error C2601: 'calculation' : local function definitions are illegal
(20): this line contains a '{' which has not yet been matched
(51): fatal error C1075: end of file found before the left brace '{'
如何解决这些错误?
推荐答案
首先:
int main(int,int) - 非标准程序入口点
int main(int, int) - very non-standard program entry point
一个:
int main (int a, int b) // print to console: 3.0*5.0=15.00
{
double a;
double b;
您正在重新定义形式参数a和b
You are redefining formal parameters a and b
这是你的编译器说的:
(7): error C2082: redefinition of formal parameter 'a'
(8): error C2082: redefinition of formal parameter 'b'
/ p>
.
int calculate (int a, int b, int c) // print to console: (7.1*8.3)-2.2=56.73
{
double a;
double b;
double c;
你有相同的局部变量和形式参数名称,我不认为这是你期望的
You have same local variables and formal parameter names, I don't think this is what you are expecting.
最后一个:
计算函数。
You are missing closing bracket "}" at the end of calculate function.
#include <iostream>
#include <iomanip>
using namespace std;
int main () // print to console: 3.0*5.0=15.00
{
double a;
double b;
a =(3.0);
b =(5.0);
cout << " " << fixed << setprecision (1) << a << "\n" << endl;
cout << "* " << b << "\n" << endl;
cout << "------" << endl;
cout << fixed << setprecision (2) << a*b << "\n" << endl;
return 0;
}
int calculate () // print to console: (7.1*8.3)-2.2=56.73
{
double a;
double b;
double c;
a = (7.1);
b = (8.3);
c = (2.2);
cout << " " << fixed << setprecision (1) << a << "\n" << endl;
cout << "* " << b << "\n" << endl;
cout << "- " << c << "\n" << endl;
cout << "------" << endl;
cout << setprecision(2) << (a*b)-c << "\n" << endl;
}
int calculation () // print to console: 3.2/(6.1*5.0)=0.10
{
double a;
double b;
double c;
a=(3.2);
b=(6.1);
c=(5.0);
cout << " " << fixed << setprecision (1) << a << "\n" << endl;
cout << b << "*" << c << endl; //how can I use variables instead of using quotes?
cout << "------" << endl;
cout << setprecision(2) << a/(b*c) << "\n" << endl;
system("PAUSE");
return 0;
}
这篇关于这个c ++程序缺少什么?打印计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!