我有这个下面的文件.我试图在visual studio 2010中运行它.但是它一直给我一个错误,说我需要包含头文件stdafx.h.但是这个文件在头文件列表中无处可见.
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
int choice();
double cylinder_volume();
double cone_volume();
double sphere_volume();
void display_result(double volume);
int main ()
{
int option;
double volume;
option=choice();
if (option==1)
{
volume=cylinder_volume();
display_result(volume);
}
else
if (option==2)
{
volume=cone_volume();
display_result(volume);
}
else
if (option==3)
{
volume=sphere_volume();
display_result(volume);
}
return 0;
}
int choice()
{
int option;
cout<<"What would you like to calculate the volume of: ";
cout<<"\nPress 1 for cylinder. ";
cout<<"\nPress 2 for cone. ";
cout<<"\nPress 3 for sphere. ";
cin>>option;
return option;
}
double cylinder_volume()
{
const double pi=3.14159;
double height,radius,volume;
cout<<"Enter the height of the cylinder: ";
cin>>height;
cout<<"\nEnter the radius of the cylinder: ";
cin>>radius;
volume=pi*radius*radius*height;
return volume;
}
double cone_volume()
{
const double pi=3.14159;
double height,radius,volume;
cout<<"Enter the height of the cone: ";
cin>>height;
cout<<"\nEnter the radius of the cone: ";
cin>>radius;
volume=(1/3)*pi*radius*radius*height;
return volume;
}
double sphere_volume()
{
const double pi=3.14159;
double radius,volume;
cout<<"\nEnter the radius of the sphere: ";
cin>>radius;
volume=(4/3)*pi*radius*radius*radius;
return volume;
}
void display_result(double volume)
{
cout<<volume;
}
Run Code Online (Sandbox Code Playgroud)
这是因为msvc默认使用预编译头,它的名字叫"stdafx.h".您应该转到"Project-> Properties"然后转到"C++ - > Precompiled header"并选择"Not using precompiled headers".下次创建新项目时,可能需要取消选中项目创建向导中的"使用预编译头"复选框.
归档时间: |
|
查看次数: |
178 次 |
最近记录: |