标题:书上的小练习就是调不出来啊!while循环中套if
取消只看楼主
hongyijia
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2006-2-20
 问题点数:0 回复次数:1 
书上的小练习就是调不出来啊!while循环中套if

p124 题2.16
有位司机记录了自己每次行驶的路程和每次耗费的汽油量。求每次加油平均一加仑汽油行多少英里。输入-1时 ,求出综 合平均数.

#include <iostream>
using std::cout;
using std::cin;
using std::endl;

int main()
{
double miles;
double gallons;
double gallons_sum=0;
double miles_sum=0;

while (gallons !=-1.0){
cout<<"Enter the gallons used (-1 to end): ";
cin>>gallons;

if (gallons =-1.0)
break;

cout<<"Enter the miles driven: ";
cin>>miles;

cout<<"The average for this time was "<<miles/gallons<<endl;

gallons_sum+=gallons;
miles_sum+=miles;
}

cout<<"The total average is "<<miles_sum/gallons_sum<<endl;

return 0;
}
它总是跳出循环,我还没输-1呢。

[此贴子已经被作者于2006-2-22 14:14:45编辑过]

搜索更多相关主题的帖子: 中套 练习 
2006-02-22 14:14
hongyijia
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2006-2-20
得分:0 
谢谢了,明天我试试
2006-02-23 00:13



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-46625-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.129633 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved