chenxie95 / SJTU_C-_Cource

上交2022小学期 程序设计思想 答疑论坛
1 stars 0 forks source link

在codeblocks上能运行,但在ICE上报错 #18

Open sjtuzyy opened 2 years ago

sjtuzyy commented 2 years ago

错误说明:error: variable or field ‘settime’ declared void error: ‘t1’ was not declared in this scope settime(t1) ; settime(t2) ;

include

using namespace std;

struct time { int hour ; int minute ; int second ; };

void settime(time &t) { cin >> t.hour >> t.minute >> t.second ; }

void increase(time *t) { if(t->second!=59) t->second += 1 ; else { t->second = 0 ; if (t->minute!=59) t->minute += 1 ; else { t->minute = 0 ; if(t->hour!=23) t->hour += 1 ; else t->hour = 0 ; } } }

void showtime(time t) { if(t.hour<10) cout << 0 << t.hour << ":" ; if(t.hour>=10) cout << t.hour << ":" ; if(t.minute<10) cout << 0 << t.minute << ":" ; if(t.minute>=10) cout << t.minute << ":" ; if(t.second<10) cout << 0 << t.second ; if(t.second>=10) cout << t.second ; }

int main() { time t1 , t2 ;

settime(t1) ; settime(t2) ;
showtime(t1) ;
cout << endl ;
increase(&t1) ;
showtime(t1) ;
cout << endl ;
showtime(t2) ;
cout << endl ;
 increase(&t2) ;
showtime(t2) ;
cout << endl ;

return 0;

}

Liangzheng-ZL commented 2 years ago

请说明是哪一个题目

sjtuzyy commented 2 years ago

请说明是哪一个题目

结构体第一题,时钟

Liangzheng-ZL commented 2 years ago

代码逻辑没问题,结构体的命名最好避免关键字,将time改成Time即可

sjtuzyy commented 2 years ago

代码逻辑没问题,结构体的命名最好避免关键字,将time改成Time即可

哦哦,明白了,codeblocks没给关键字提示,谢谢助教