注册 登录
编程论坛 C++教室

菜鸟求助,关键是公式还不熟悉

才才 发布于 2012-10-16 10:20, 483 次点击
1。通过cin输入两个时,分,秒数据。计算出每一时,分,秒距离0时0分0秒的总秒数。并求两个总秒数差的绝对值。
2.写程序,从键盘输入立方形三条边长,计算立方体的面积和体积。
9 回复
#2
才才2012-10-16 10:40
#include <iostream>
 
using namespace std;
 
int main()
 {
     int a,b,c,area,size;
     cout<<"请输入三个整数:"<<endl;
     cin>>a>>b>>c;
     area=a*b*2+b*c*2+a*c*2;
     size=a*b*c;
     cout<<"The area of "<<a<<" , "<<b<<" and "<<c<<" is:"<<area<<endl;
      cout<<"The size of "<<a<<" , "<<b<<" and "<<c<<" is:"<<size<<endl;
     return 0;
}
#3
才才2012-10-16 10:41
cout<<"The area of "<<a<<" , "<<b<<" and "<<c<<" is:"<<area<<endl;
       cout<<"The size of "<<a<<" , "<<b<<" and "<<c<<" is:"<<size<<endl;
这里可以写简单点吗?
#4
才才2012-10-16 10:52
第一个还不会,谁帮我讲讲啊
#5
才才2012-10-16 11:04
#include <iostream>
 
using namespace std;
 
int main()
 {
     int a,b,c,area,size;
     cout<<"请输入三个整数:"<<endl;
     cin>>a>>b>>c;
     area=a*b*2+b*c*2+a*c*2;
     size=a*b*c;
     cout<<area<<endl;
      cout<<size<<endl;
     return 0;
}
上面哪里有错???/为什么不能执行?
#6
闯荡江湖882012-10-16 14:35
加一个头

#include "stdafx.h"
#7
wuchunbing2012-10-16 21:03
我运行了5楼的程序 没有错误 不知道你用是什么编译软件 我就是一个建议 :1、既然是立方体 肯定3条边长相等 不用定义那么多变量  2、立方体边长未必就是整数 应该用float来定义吧。 我是吹毛求疵了 别生气哈
#8
wuchunbing2012-10-16 21:41
#include <iostream>
using namespace std;
int main()
{
    int a,b,c,d;
    int a1,b1,c1,d1;
    cout<<"输入的时间最好为两位数:\n"<<endl;
    cin>>a>>b>>c;
    cin>>a1>>b1>>c1;
    if(a>=0&&a<24&&b>=0&&b<60&&c>=0&&c<60)
    {d=(23-a)*3600+(59-b)*60+(60-c);
    cout<<"距离0时0分0秒还有:"<<d<<"秒"<<endl;
    }
    else
    cout<<"你好瓜哦连时间都不知道吗?"<<endl;

    if(a1>=0&&a1<24&&b1>=0&&b1<60&&c1>=0&&c1<60)
    {d1=(23-a1)*3600+(59-b1)*60+(60-c1);
    cout<<"距离0时0分0秒还有:"<<d1<<"秒"<<endl;
    }
    else
        cout<<"你好瓜哦连时间都不知道吗?"<<endl;
    int e;
    if (d>d1)
        e=d-d1;
    else
        e=d1-d;
    cout<<e<<endl;

}
以上是第一题,纯个人意见,多指正。
#9
才才2012-10-17 22:51
if(a>=0&&a<24&&b>=0&&b<60&&c>=0&&c<60)
&&&&&&&什么含义
#10
wuchunbing2012-10-18 11:17
如果:0=<a<24
      0=<b<60
      0=<c<60
这3个条件都成立的话,继续执行下面的语句。
&&是且的意思
1