無限ループさせる方法教えてください

フォーラム(掲示板)ルール
フォーラム(掲示板)ルールはこちら  ※コードを貼り付ける場合は [code][/code] で囲って下さい。詳しくはこちら

トピックに返信する


答えを正確にご入力ください。答えられるかどうかでスパムボットか否かを判定します。

BBCode: ON
[img]: ON
[flash]: OFF
[url]: ON
スマイリー: OFF

トピックのレビュー
   

展開ビュー トピックのレビュー: 無限ループさせる方法教えてください

Re: 無限ループさせる方法教えてください

#3

by みけCAT » 4年前

ゆんゆん さんが書きました:
4年前
breakを消してみたんですができなくてどうしてもやり方がわかりません
何がしたいのですか?
「無限ループさせる」だけなら、今あるコードを全部消して

コード:

int main(void) {
	for(;;);
}
だけで良いでしょう。
あたっしゅ さんが書きました:
4年前

コード:

	} while ((choice1 < 1) || (choice1 > 4));

	return 0;
}

コード:

	} while ((choice1 >= 1) || (choice1 <= 4));

	return 0;
}
にすればいいんじゃねーの ?
全ての整数は1以上または4以下なので、こうすると常に成り立つ条件式になる、ということですね。
もっとシンプルに

コード:

	} while (1);

	return 0;
}
としてもいいでしょう。

Re: 無限ループさせる方法教えてください

#2

by あたっしゅ » 4年前

>int main()
>{
>ほ
>int choice1;
>int choice2;

「ほ」って、何 ?

ま、ゴミだろ。

 ソースコードは、

rules フォーラム(掲示板)ルール

にあるように、半角の[CODE][/CODE]で囲って。
って、Windows 10 の Microsoft Visual Studio Community 2019 Version 16.1.3 にぶっ込んだら、
自動インデントされたわ。

コード:

	} while ((choice1 < 1) || (choice1 > 4));

	return 0;
}

コード:

	} while ((choice1 >= 1) || (choice1 <= 4));

	return 0;
}
にすればいいんじゃねーの ?

あと

コード:

	//printf("\n\n[1]What do you want to see?\n");
	//printf("1. The 1980's\n");
	//printf("2. The 1990's\n");
	//printf("3. The 2000's\n");
	//printf("4. Quit\n");

	do
	{
		printf("\n\n[1]What do you want to see?\n");
		printf("1. The 1980's\n");
		printf("2. The 1990's\n");
		printf("3. The 2000's\n");
		printf("4. Quit\n");
とかか ?

無限ループさせる方法教えてください

#1

by ゆんゆん » 4年前

breakを消してみたんですができなくてどうしてもやり方がわかりません
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <stdlib.h>

int main()
{

int choice1;
int choice2;


printf("\n\n[1]What do you want to see?\n");
printf("1. The 1980's\n");
printf("2. The 1990's\n");
printf("3. The 2000's\n");
printf("4. Quit\n");

do
{
printf("[1]Enter your choice: ");
scanf(" %d", &choice1);
switch (choice1)
{

case (1):
{
printf("\n\n[2.1]What would you like to see?\n");
printf("1. Baseball\n");
printf("2. The Movies\n");
printf("3. US Presidents\n");
printf("4. Quit\n");
printf("[2.1]Enter your choice: ");
scanf(" %d", &choice2);
if (choice2 == 1)
{
printf("\nWorld Series Champions ");
printf("of the 1980s:\n");
printf("1980: Philadelphia Phillies\n");
printf("1981: Los Angeles Dodgers\n");
printf("1982: St. Louis Cardinals\n");
printf("1983: Baltimore Orioles\n");
printf("1984: Detroit Tigers\n");
printf("1985: Kansas City Royals\n");
printf("1986: New York Mets\n");
printf("1987: Minnesota Twins\n");
printf("1988: Los Angeles Dodgers\n");
printf("1989: Oakland A's\n");
break;
} else if (choice2 == 2)
{
printf("\nOscar-Winning Movies in the 1980s:\n");
printf("1980: Ordinary People\n");
printf("1981: Chariots of Fire\n");
printf("1982: Gandhi\n");
printf("1983: Terms of Endearment\n");
printf("1984: Amadeus\n1985: Out of Africa\n");
printf("1986: Platoon\n");
printf("1987: The Last Emperor\n");
printf("1988: Rain Man\n");
printf("1989: Driving Miss Daisy\n");
break;
} else if (choice2 == 3)
{
printf("\nUS Presidents in the 1980s:\n");
printf("1980: Jimmy Carter\n");
printf("1981-1988: Ronald Reagan\n");
printf("1989: George Bush\n");
break;
} else if (choice2 == 4)
{
exit(1);
} else
{
printf("Sorry, that is not a valid choice!\n");
break;
}
}


case (2):
{
printf("\n\n[2.2]What would you like to see?\n");
printf("1. Baseball\n");
printf("2. The Movies\n");
printf("3. US Presidents\n");
printf("4. Quit\n");
printf("[2.2]Enter your choice: ");

scanf(" %d", &choice2);
if (choice2 == 1)
{
printf("\nWorld Series Champions of ");
printf("the 1990s:\n");
printf("1990: Cincinnati Reds\n");
printf("1991: Minnesota Twins\n");
printf("1992: Toronto Blue Jays\n");
printf("1993: Toronto Blue Jays\n");
printf("1994: No World Series\n");
printf("1995: Atlanta Braves\n");
printf("1996: New York Yankees\n");
printf("1997: Florida Marlins\n");
printf("1998: New York Yankees\n");
printf("1999: New York Yankees\n");
break;
} else if (choice2 == 2)
{
printf("\nOscar-Winning Movies in ");
printf("the 1990s:\n");
printf("1990: Dances with Wolves\n");
printf("1991: The Silence of the Lambs\n");
printf("1992: Unforgiven\n");
printf("1993: Schindler's List\n");
printf("1996: The English Patient\n");
printf("1997: Titanic\n");
printf("1998: Shakespeare in Love\n");
printf("1999: American Beauty\n");
break;
} else if (choice2 == 3)
{
printf("\nUS Presidents in the 1990s:\n");
printf("1990-1992: George Bush\n");
printf("1993-1999: Bill Clinton\n");
break;
} else if (choice2 == 4)
{
exit(1);
} else
{
printf("Sorry, that is not a valid choice!\n");
break;
}
}

case (3):
{
printf("\n\n[2.3]What would you like to see?\n");
printf("1. Baseball\n");
printf("2. The Movies\n");
printf("3. US Presidents\n");
printf("4. Quit\n");
printf("[2.3]Enter your choice: ");
scanf(" %d", &choice2);

if (choice2 == 1)
{
printf("\nWorld Series Champions of ");
printf("the 2000s:\n");
printf("2000: New York Yankees\n");
printf("2001: Arizona Diamondbacks\n");
printf("2002: Anaheim Angels\n");
printf("2003: Florida Marlins\n");
printf("2004: Boston Red Sox\n");
printf("2005: Chicago White Sox\n");
printf("2006: St. Louis Cardinals\n");
printf("2007: Boston Red Sox\n");
printf("2008: Philadelphia Phillies\n");
printf("2009: New York Yankees\n");
break;
} else if (choice2 == 2)
{
printf("\nOscar-Winning Movies in ");
printf("the 2000s:\n");
printf("2000: Gladiator\n");
printf("2001: A Beautiful Mind\n");
printf("2002: Chicago\n2003: The ");
printf("Lord of the Rings: The Return of the King\n");
printf("2004: Million Dollar Baby\n");
printf("2005: Crash\n");
printf("2006: The Departed\n");
printf("2007: No Country for Old Men\n");
printf("2008: Slumdog Millionaire\n");
printf("2009: The Hurt Locker\n");
break;
} else if (choice2 == 3)
{
printf("\nUS Presidents in the 2000s:\n");
printf("2000: Bill Clinton\n");
printf("2001-2008: George Bush\n");
printf("2009: Barrack Obama\n");
break;
} else if (choice2 == 4)
{
exit(1);
} else
{
printf("Sorry, that is not a valid choice!\n");
break;
}
}
case (4):
exit (1);
default:
printf("%d is not a valid choice.\n", choice1);
printf("Try again.\n");
break;
}
} while ((choice1 < 1) || (choice1 > 4));

return 0;
}

ページトップ