C 编程问题
Problems with the C++ programming
我有以下文件。我正在尝试在2010年Visual Studios中运行它。但是它不断给我一个错误,说我需要包括标题文件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;
}
这是因为MSVC默认使用预编译标头,并且名为" stdafx.h"。您应该转到" Project->属性",然后转到" C ->预编译标头",然后选择"不使用预编码标题"。下次您创建新项目时,您可能需要取消选中"使用预编译标题"复选框中的"项目创建向导"。
相关文章:
- C++模板编程设计问题 - 根据输入文件返回不同的类型
- Frank Luna 在他的书"使用 DirectX12 进行 3D 游戏编程"的介绍中盒子示例的问题
- 此动态编程问题的自上而下方法
- 返回不停止函数,递归函数问题?(编程练习,动态规划,Levenshtein 回溯)
- 寻找解决这个动态编程问题的提示
- 面临在 if 语句之外打印变量数据的问题 完成使用 Qt 编程
- 竞争性编程问题说错了答案
- 模板编程初学者问题
- 使用虚幻引擎4编程的平台游戏中的偏转问题
- 以编程方式锁定注册表项以避免并发问题
- 如何解决在使用动态 2D 数组进行矩阵乘法的 MPI 进行并行编程时的问题
- 编程:原理与实践 使用C++ 第 4 章演练步骤 6:关于数字范围的一般问题
- 我在用c ++编程时一直遇到LNK2005错误,我似乎无法弄清楚问题是什么
- 罗马数字C++编程转换问题
- 编程问题和概念
- 问题是关于C 的数组,以便在编程主题中有更多的了解
- Stroustrup的代码审查-编程原理-Ch-4-问题:3-错误:矢量下标超出范围
- 代码块上的编译器标志出现问题.编程初学者
- 由于基于接口的编程,遇到 C++ 虚拟模板函数问题
- 有没有更好的方法来解决这个问题 - 编程原理和实践使用C++:第 4 章 - 演练?