|

楼主 |
发表于 2022-9-15 21:39:46
|
显示全部楼层
我的代码:
- #include <stdio.h>
- #include "ssebtr1.h"
- int main()
- {
- int i,time,BPM,rate,age;
- printf("请输入年龄:\n");
- scanf("%d",&age);
- rate=220-age;
- BPM=150;
- playSound(BPM);
- i=getHeartRate();
- if(i>rate)
- {
- printf("请马上停止脚步,否则有生命危险...\n");
- return -1;
- }
- else if(i>=rate*0.85&&i<rate)
- {
- printf("请放慢脚步\n");
- BPM=BPM-20;
- playSound(BPM);
- return 0;
- }
- else if(i<rate*0.85&&i>=rate*0.75)
- {
- printf("Come on,请加快节奏\n!");
- BPM=BPM+20;
- playSound(BPM);
- return 0;
- }
- else
- {
- playSound(BPM);
- return 0;
- }
- return 0;
- }
复制代码
小甲鱼的代码:
- #include <stdio.h>
- #include "ssebtr1.h"
- int main()
- {
- int age, max_hr, bpm, hr; // hr即HeartRate,心率的意思
- printf("请输入您的年龄:");
- scanf("%d", &age);
- max_hr = 220 - age;
- bpm = 150;
- playSound(bpm);
- hr = getHeartRate();
- if (hr > max_hr)
- {
- printf("请马上停止跑步,否则会有绳命危险……\n");
- }
- else if (hr > max_hr * 0.85)
- {
- printf("请放慢脚步\n");
- bpm = bpm - 20; // 注意,这里需要先修改bpm的值
- playSound(bpm); // 你不能在这里传入bpm-20
- }
- else if (hr < max_hr * 0.75)
- {
- printf("Come on,请加快节奏!\n");
- bpm = bpm + 20;
- playSound(bpm);
- }
- else
- {
- playSound(bpm);
- }
- return 0;
- }
复制代码
通过调用 playSound() 函数播放指定节奏的音乐。
该函数有一个参数,用于指定待播放音乐的 BPM(次心跳/分钟);如果该函数成功调用并播放,返回值为 0,如果找不到对应 BPM 的音乐或调用失败,返回值为 -1。
这句话怎么翻译呢,我认为返回就用return,所以用了好多return |
|