int main(void) {
//宣告變數
int ShapeOption=0; //使用者選擇形狀的變數
char want_to_continue = 'y'; //使用者選擇是否繼續的字元
int i=1; //使用者使用該程序次數之變數
//修正(前)
char new_line = 'y';
//執行程式(變數指定;比較變數是否符合前面的指定;次數累加)2符合則回圈,否則跳脫//[i++]=[i+1]
for (want_to_continue = 'y';want_to_continue == 'y';i++) {
//顯示使用者重複的次數
printf("這是第 %d 次執行\n",i);
//引導使用者輸入
printf("按1畫矩形,否則畫三角形:");
//使用者輸入
scanf_s("%d",&ShapeOption);
//如果使用者按1
if (ShapeOption==1) {
//畫矩形
printf("+----+\n");
printf("| |\n");
printf("+----+\n");
}
//否則
else {
//畫三角形
printf(" /\\ \n");
printf(" / \\ \n");
printf(" +----+ \n");
}
//修正(後)
scanf("%c",&new_line);
//引導使用者輸入
printf("是否要繼續,若要繼續案y,結束案n.:");
//使用者輸入
scanf("%c",&want_to_continue);
}
return 0;
}
******************************************************************************/
#include <stdio.h>
int main(void) {
//宣告變數
int ShapeOption=0; //使用者選擇形狀的變數
char want_to_continue = 'y';
//修正(前)
char new_line = 'y';
//執行程式
do {
//引導使用者輸入
printf("按1畫矩形,否則畫三角形:");
//使用者輸入
scanf_s("%d",&ShapeOption);
//如果使用者按1
if (ShapeOption==1) {
//畫矩形
printf("+----+\n");
printf("| |\n");
printf("+----+\n");
}
//否則
else {
//畫三角形
printf(" /\\ \n");
printf(" / \\ \n");
printf(" +----+ \n");
}
//修正(後)
scanf("%c",&new_line);
//引導使用者輸入
printf("是否要繼續,若要繼續案y,結束案n.:");
//使用者輸入
scanf("%c",&want_to_continue);
}
//如果使用者按y繼續(while存在),否則結束
while (want_to_continue == 'y');
return 0;
}
******************************************************************************/
#include <stdio.h>
int main(void) {
//宣告變數
int ShapeOption=0; //使用者選擇形狀的變數
char want_to_continue = 'y';
//修正前
char new_line = 'y';
while (want_to_continue == 'y') {
//引導使用者輸入
printf("按1畫矩形,否則畫三角形:");
//使用者輸入
scanf_s("%d",&ShapeOption);
//使用者按1
if (ShapeOption==1) {
//畫矩形
printf("+----+\n");
printf("| |\n");
printf("+----+\n");
}
//使用者按2
else {
//畫三角形
printf(" /\\ \n");
printf(" / \\ \n");
printf(" +----+ \n");
}
//修正後
scanf("%c",&new_line);
//引導使用者輸入
printf("是否要繼續,若要繼續案y,結束案n.:");
//使用者輸入
scanf("%c",&want_to_continue);
}
return 0;
}
******************************************************************************/
#include <stdio.h>
int main(void) {
char new_line;
//宣告變數
int ShapeOption; //使用者選擇形狀的變數
int rectangle_option; //使用者選擇矩形的大小
int triangle_option;//使用者選擇三角形的大小
//引導使用者輸入
printf("按1畫矩形,按2畫三角形:");
//使用者輸入
scanf("%d",&ShapeOption);
//使用者按1
if(ShapeOption==1) {
//引導使用者輸入
printf("按1畫小矩形,按2中畫矩形,按3大畫矩形:");
//使用者輸入
scanf_s("%d",&rectangle_option);
if(rectangle_option==1) {
//畫小矩形
printf("+----+\n");
printf("| |\n");
printf("+----+\n");
}
else if (rectangle_option==2) {
//畫中矩形
printf("+------+\n");
printf("| |\n");
printf("| |\n");
printf("+------+\n");
}
else if (rectangle_option==3) {
//畫大矩形
printf("+--------+\n");
printf("| |\n");
printf("| |\n");
printf("| |\n");
printf("+--------+\n");
}
}
//使用者按2
else if (ShapeOption==2) {
//引導使用者輸入
printf("按1畫小三角形,按2中畫三角形,按3大畫三角形:");
//使用者輸入
scanf_s("%d",&triangle_option);
if(triangle_option==1) {
//畫小三角形
printf(" /\\ \n");
printf(" / \\ \n");
printf(" +----+ \n");
}
else if (triangle_option==2) {
//畫中三角形
printf(" /\\ \n");
printf(" / \\ \n");
printf(" / \\ \n");
printf("+------+ \n");
}
else if (triangle_option==3) {
//畫大三角形
printf(" /\\ \n");
printf(" / \\ \n");
printf(" / \\ \n");
printf(" / \\ \n");
printf("+--------+ \n");
}
}
scanf("%c",&new_line);
return 0;
}
******************************/
task main (){
SetSensorLight (IN_1);
SetSensorTouch (IN_2);
int continue_criterion = 1;
while (continue_criterion == 1) {
NumOut(0,LCD_LINE1,Sensor(IN_1));
NumOut(0,LCD_LINE2,Sensor(IN_2));
Wait (200);
if (Sensor(IN_1)>30){
OnFwd(OUT_AC,75);
}
else if (Sensor(IN_1)>30 && Sensor(IN_2)==1) {
OnFwd(OUT_A,75);
OnRev(OUT_C,75);
}
}
}
*********************************************************************************/
task main(){
//宣告變數
int switch_no;
//開啟感測器
SetSensorLight(IN_1);
SetSensorTouch(IN_2);
NumOut(0, LCD_LINE1, Sensor(IN_1));
NumOut(0, LCD_LINE2, Sensor(IN_2));
Wait(1000);
if(Sensor(IN_1)>30){ //狀況1桌面淺色:直走
switch_no=1;
}
else if(Sensor(IN_1)<30 && Sensor(IN_2)==1){ //狀況2桌面深色且碰到東西:原地旋轉
switch_no=2;
}
//執行內容
switch(switch_no){
case 1:
{
OnFwd(OUT_AC,75);
Wait(2000);
}
break;
case 2:
{
OnFwd(OUT_A,75);
OnRev(OUT_C,75);
Wait(2000);
}
break;
}
}
沒有留言:
張貼留言