zhangminglong_ 2020-06-17 14:59 采纳率: 100%
浏览 150

C++怎样设置可读写的全局变量

怎么样定义一个可读写的全局变量,比如我代码中的变量yu

#include<iostream>
#define yu;
int day(int);
int hour(int);
int minute(int);
int second(int);
const int stom = 60;
const int mtoh = 60;
const int htod = 24;

int main(){
    using namespace std;
    cout << "Enter the number of seconds: ";
    long seconds;
    cin >> seconds;
    cout << seconds << " seconds = " << day(seconds) << " days, "
    << hour(seconds) << " hours, " << minute(seconds) 
    << " minutes, " << second(seconds) << " seconds." << endl;
    return 0; 
}
int day(int s){
    int d;
    d = s /stom / mtoh / htod;
    return d;
}
int hour(int s){
    int h;
    yu = s %(stom * mtoh * htod);
    h = yu / stom / mtoh;
    return h;
}
int minute(int s){
    int m;
    yu = yu %(stom * mtoh);
    m = yu / stom;
    return 0;
}
int second(int s){
    int se;
    se = yu % stom;
    return se;
}

求大神指教

  • 写回答

1条回答 默认 最新

  • 石头与代码 2020-06-17 15:14
    关注

    这是纯C的问题吧,虽然不知道你想做什么,定义一个全局yu
    #define yu; 请替换为
    int yu = 0;
    另外建议改
    const int stom = 60;
    const int mtoh = 60;
    const int htod = 24;

    #define STOM 60

    评论

报告相同问题?

悬赏问题

  • ¥15 两台交换机分别是trunk接口和access接口为何无法通信,通信过程是如何?
  • ¥15 C语言使用vscode编码错误
  • ¥15 用KSV5转成本时,如何不生成那笔中间凭证
  • ¥20 ensp怎么配置让PC1和PC2通讯上
  • ¥50 有没有适合匹配类似图中的运动规律的图像处理算法
  • ¥15 dnat基础问题,本机发出,别人返回的包,不能命中
  • ¥15 请各位帮我看看是哪里出了问题
  • ¥15 vs2019的js智能提示
  • ¥15 关于#开发语言#的问题:FDTD建模问题图中代码没有报错,但是模型却变透明了
  • ¥15 uniapp的h5项目写一个抽奖动画