Notes from the second day

do while循环

语法:do{

循环语句块;

} while(表达式);

do while循环的特点:

一.循环至少执行一次,使用场景有限。

二.循环在前(do),条件在后(while)

范例

#include <stdio.h>

int main() {

int score = -1;

do {

printf("请输入考试成绩:[0,100]");

scanf("%d", &score);

} while (score < 60);

printf("恭喜您,通过考试!");

return 0;

}

练习:小灰猜数字游戏

#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

// 主菜单

void menu() {

printf("-----------小灰猜数字--------\n");

printf("------1、play 0、exit-----\n");

printf("-----------------------------\n");

}

// 游戏功能

void game() {

}

int main() {

int search;

do {

menu();

printf("请选择:");

scanf("%d", &search);

switch (search) {

case 1:

game();

break;

case 0:

printf("欢迎再来!\n");

break;

default:

printf("输入错误,重新输入\n");

}

} while (search);

return 0;

}

// 游戏功能代码

void game() {

// 电脑随机产生一个需要猜出的数

// 重新播种

srand((unsigned)time(NULL));

// 生成指定范围内的随机数[1,100]

int num = rand() % 100 + 1;

int count = 0;

for (;;) {

count++;

printf("小灰猜的数字1~100:");

int guessNum;

scanf("%d", &guessNum);

if (guessNum > num) {

printf("猜大了\n");

}

else if (guessNum < num) {

printf("猜小了\n");

}

else {

printf("恭喜您,猜对了,总共猜了%d次。", count);

break;

}

}

}

循环的重点是循环的嵌套使用,在使用时应该注意循环的条件和逻辑,还有变量名的更新

The OpenStack Foundation supported the creation of this book with plane tickets to Austin, lodging (including one adventurous evening without power after a windstorm), and delicious food. For about USD $10,000, we could collaborate intensively for a week in the same room at the Rackspace Austin office. The authors are all members of the OpenStack Foundation, which you can join. Go to the Foundation web site. We want to acknowledge our excellent host Rackers at Rackspace in Austin: Emma Richards of Rackspace Guest Relations took excellent care of our lunch orders and even set aside a pile of sticky notes that had fallen off the walls. Betsy Hagemeier, a Fanatical Executive Assistant, took care of a room reshuffle and helped us settle in for the week. The Real Estate team at Rackspace in Austin, also known as “The Victors,” were super responsive. Adam Powell in Racker IT supplied us with bandwidth each day and second monitors for those of us needing more screens. On Wednesday night we had a fun happy hour with the Austin OpenStack Meetup group and Racker Katie Schmidt took great care of our group. We also had some excellent input from outside of the room: Tim Bell from CERN gave us feedback on the outline before we started and reviewed it mid-week. Sébastien Han has written excellent blogs and generously gave his permission for re-use. Oisin Feeley read it, made some edits, and provided emailed feedback right when we asked. Inside the book sprint room with us each day was our book sprint facilitator Adam Hyde. Without his tireless support and encouragement, we would have thought a book of this scope was impossible in five days. Adam has proven the book sprint method effectively again and again. He creates both tools and faith in collaborative authoring at www.booksprints.net. We couldn’t have pulled it off without so much supportive help and encouragement.
07-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值