当前位置:编程学习 > C/C++ >>

哪位大神帮我看看这段C语言代码有什么问题

// k2.cpp : 定义控制台应用程序的入口点。// #include <stdafx.h> #include<iostream> using namespace std; double lar(); int main() { while(1) { cout<<"功能:1.大型车验条 0.退出系统 "<<endl; cout<<"请选择:"; int a; cin>>a; switch(a) { case 1: lar(); break; case 0: exit(0); default: cout<<"输入错误!"<<endl; } system("pause"); system("cls"); } return 0; } double lar() { double distance; double lardistance=0; cout<<"请输入公里数:"; cin>>distance; cout<<"费用为:%.2f元\n", distance*0.5; return 0; } 程序可以运行,但是运算结果都是.2f,没有运算,到底是哪里的问题啊?
答案:输出变量那一句改一下:
cout<<"费用为:"<<distance*0.5<<"元\n";


cout不用指定类型,和printf不同
其他:cout<<"费用为:%.2f元\n", distance*0.5;不能这样写,改为:cout<<"费用为:"<<distance*0.5<<endl; cout<<"费用为:"<<distance*0.5<<"元"<<endl;



c++和c的输出不一样。 

上一个:帮帮我做这道题吧·main() {char c=`z`; pintf("%c\n".c-25); } 输出结果是什么额?谢谢大家了
下一个:世界最牛的语言大师是谁????

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,