我很久以前就开始使用C ++了,我在理解为什么似乎无法在main之外创建两个函数时遇到了问题。当我只有1,一切都很好,第二个我加第二个,这是远一个,告诉我放一个;在我的cel函数声明之后......
// Lab03.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
int main()
{
double celcius(int);
double far(int);
std::cout<<"DEGREE DE FAR A CEL\n";
for (int i=32; i<213; i++)
{
std::cout.precision(3);
std::cout<<i<<"F = " <<celcius(i)<<"C ";
if ((i+1)%4==0)
{
std::cout<<"\n";
}
std::cout<<"\n\n\nDEGREE DE CEL A FAR\n";
for (int i=0; i<101; i++)
{
std::cout.precision(3);
std::cout<<i<<"C = " <<far(i)<<"C ";
if ((i+1)%4==0)
{
std::cout<<"\n";
}
}
_gettch();
return 0;
}
double celcius(int n)
{
double endcel;
endcel= (n-32.0)*(5.0/9.0);
return endcel;
}
double far(int o)
{
double endfar=(o*(9/5))+32;
return endfar;
}
答案 0 :(得分:2)
看起来你错过了一个结束}来关闭你的主要功能就在celcius功能之前。
正确的代码缩进将帮助您在将来找到这样的问题。
// Lab03.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
int main() {
double celcius(int);
double far(int);
std::cout<<"DEGREE DE FAR A CEL\n";
for (int i=32; i<213; i++) {
std::cout.precision(3);
std::cout<<i<<"F = " <<celcius(i)<<"C ";
if ((i+1)%4==0) {
std::cout<<"\n";
}
std::cout<<"\n\n\nDEGREE DE CEL A FAR\n";
for (int i=0; i<101; i++) {
std::cout.precision(3);
std::cout<<i<<"C = " <<far(i)<<"C ";
if ((i+1)%4==0) {
std::cout<<"\n";
}
}
_gettch();
return 0;
}
}
double celcius(int n) {
double endcel;
endcel= (n-32.0)*(5.0/9.0);
return endcel;
}
double far(int o) {
double endfar=(o*(9/5))+32;
return endfar;
}