本文介绍了我收到一条评论“id返回1退出状态。我做错了什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include< stdio.h>
#include< stdlib.h> //记得如果你打算使用exit(),你需要
//这个头文件
main()
{
//尽管是一个很长的程序,你只需要两个变量:
//第一个菜单一个,第二个菜单一个
int choice1;
int choice2;
//潜在的十年选择
printf(你想看到什么?\ n);
printf(1. 1980年代\ n);
printf(2. 1990年代\ n);
printf(3。2000年代\ n);
printf(4.Quit\\\
);
//顶部菜单选项和使
//得到
//信息的switch语句包含在
/的do-while循环中/确保四个菜单选项中的一个
//
do
{
printf(输入您的选择:);
scanf(%d,& choice1);
开关(choice1)
{
//在第一种情况下,用户选择了1980年代。现在它是
//时间来查看他们需要什么具体信息。
case(1):
{
printf(\ n你想看到什么?\ n);
printf(1。Baseball \ n);
printf(2.the movies\);
printf(3.美国总统);
printf(4.Quit\\\
);
printf(输入您的选择:);
scanf(%d,& choice2);
if(choice2 == 1)
{
printf(\ n \\\
nWorld Series Chapions);
printf(1980年代:\ n);
printf(1980:Philadelphia Phillies\\\
);
printf(1981:Los Angeles Dodgers \ n);
printf(1982:St. Louis Cardinals\\\
);
printf(1983:Baltimore Orioels \ 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);
printf(\ n \ nn \ n);
休息;
}否则if(choice2 == 2)
{
printf(1980年代的\ n \ nnOscar赢得电影:\ n);
printf(1980:Ordinary People\\\
);
printf(1981:Chariots of Fire \ n);
printf(1982:Ghandi \ n);
printf(1983:Endearment的条款);
printf(1984:Amadeus \ n);
printf(1985:Out of Africa\\\
);
printf(1986:Platoon \ n);
printf(1987:The Last Emperor \ n);
printf(1988:Rain man \ n);
printf(1989:驾驶Miss Daisy);
printf(\ n \ nn \ n);
休息;
}否则if(choice2 == 3)
{
printf(1980年代的美国总统:\ n);
printf(1980:Jimmy Carter \ n);
printf(1981-1988:Ronald Reagen \ n);
printf(1989:George Bush \ n);
printf(\ n \ nn \ n);
休息;
}否则if(choice2 == 4)
{
exit(1);
}其他
{
printf(抱歉,这不是一个有效的选择!\ n);
休息;
}
}
//这是1990年代的情况。
//与顶层菜单不同,没有数据验证
// do-while循环
case(2):
{
printf(\ n \ n你想看到什么?\ n);
printf(1。Baseball \ n);
printf(2.the movies\);
printf(3。美国Presidients \ n);
printf(4.Quit\\\
);
printf(输入你的选择:);
scanf(%d,& choice2);
if(choice2 == 1)
{
printf(\ n \ n世界系列赛冠军);
printf(1990年代:\ n);
printf(1990:Cincinatti reds\\\
);
printf(1991:Minnesota Twins \ n);
printf(1992:Toronto Blue jays\\\
);
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 Yankess \ n);
printf(\ n \ nn \ n);
休息;
}否则如果(choice2 == 2)
{
printf(\ n \ n,奥斯卡获奖电影);
printf(1990年代:\ n);
printf(1990:与狼共舞);
printf(1991:The Silence of the Lambs \ n);
printf(1992:Unforgiven \ n);
printf(1993:Schindlers List \\\
);
printf(1994:?\ n);
printf(1995:?? \ n);
printf(1996:The English Patient \ n);
printf(1997:Titanic \ n);
printf(1998:Shakespere in Love\ n);
printf(1999:American Beauty \ n);
printf(\ n \ nn \ n);
休息;
}否则if(choice2 == 3)
{
printf(1990年代的\ n \ nnUS总统:\ n);
printf(1990-1992:George Bush \ n);
printf(1993-1999:Bill Clinton \ n);
printf(\ n \ nn \ n);
休息;
}否则if(choice2 == 4)
{
exit(1);
}其他
{
printf(抱歉,这不是一个有效的选择!\ n);
休息;
}
}
//用户选择2000年
案例的部分(3):
{
printf(你想看到什么?\ n);
printf(1。Baseball \ n);
printf(2.The Movies \ n);
printf(3.美国总统);
printf(4.Quit\\\
);
printf(输入您的选择:);
scanf(%d,& choice2);
if(choice2 == 1)
{
printf(\ n \ nnWorld series Champions of);
printf(The 2000's:\ 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);
printf(2006:St. Louis Cardinals\\\
);
printf(2007:Boston Red Sox \ n);
printf(2008:Philadelphia Phillies\\\
);
printf(2009:New York Yankees \ n);
printf(\ n \ nn \ n);
休息;
}否则如果(choice2 == 2)
{
printf(\ n \ nnOscar赢得电影);
printf(2000年代:\ n);
printf(2000:Gladiator\\\
);
printf(2001:A Beautiful Mind \ n);
printf(2002:Chicago \ n);
printf(2003:指环王之家);
printf(2004:Million Dollar Baby \ n);
printf(2005:Crash \ n);
printf(2006:The Deeded\\\
);
printf(2007:没有老人的国家);
printf(2008:Slumdog Millionaire \ n);
printf(2009:The Hurt Locker \ n);
printf(\ n \ nn \ n);
休息;
}否则if(choice2 == 3)
{
printf(\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n'中的总统);
printf(2000:Bill Clinton \ n);
printf(2001-2008:George W Bush \ n);
printf(2009:Barack Obama \ n);
printf(\ n \ nn \ n);
休息;
}否则if(choice2 == 4)
{
exit(1);
}其他
{
printf(抱歉,这不是一个有效的选择!\ n);
休息;
}
}
case(4):
exit(1);
默认值:printf(\ n%d不是有效的选择。\ n);
printf(再试一次。\ n);
休息;
}
} while((choice1< 1)||(choice1> 4));
返回0;
}
我的尝试:
我试过查看程序并且没有明显的事情发生。
解决方案
#include <stdio.h> #include <stdlib.h> // remember if you plan to use exit(), you need // this header file main() { // Despite being a long program, you only need two variables: // one for the first menu and one for the second menu int choice1; int choice2; // The potential decade choices printf("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"); //The top menu choice and the switch statement that makes the // resulting //information appear are encased in a do-while loop that //ensures one // of the four menu choices are made do { printf("Enter your choice: "); scanf(" %d", &choice1); switch (choice1) { //In the first case, the user picked the 1980's. Now it //time to see what specific info they need. case (1) : { printf("\nWhat 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("Enter your choice: "); scanf(" %d", &choice2); if (choice2 ==1) { printf("\n\nWorld Series Chapions "); printf(" of the 1980's:\n"); printf("1980: Philadelphia Phillies\n"); printf("1981: Los Angeles Dodgers\n"); printf("1982: St. Louis Cardinals\n"); printf("1983: Baltimore Orioels\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"); printf("\n\n\n"); break; } else if (choice2 == 2) { printf("\n\nOscar winning movies in the 1980's:\n"); printf("1980: Ordinary People\n"); printf("1981: Chariots of Fire\n"); printf("1982: Ghandi\n"); printf("1983: Terms of Endearment\n"); printf("1984: Amadeus\n"); printf("1985: Out of Africa\n"); printf("1986: Platoon\n"); printf("1987: The Last Emperor\n"); printf("1988: Rain man\n"); printf("1989: Driving Miss Daisy"); printf("\n\n\n"); break; } else if (choice2 == 3) { printf("\n\n US Presidents in the 1980's:\n"); printf("1980: Jimmy Carter\n"); printf(" 1981-1988: Ronald Reagen\n"); printf("1989: George Bush\n"); printf("\n\n\n"); break; } else if (choice2 == 4) { exit(1); } else { printf("Sorry, that is not a valid choice!\n"); break; } } //This is the case for the 1990's. // Unlike the top menu, there isn't a data validation //do-while loop case (2) : { printf("\n\n What would you like to see?\n"); printf("1. Baseball\n"); printf("2. The movies\n"); printf("3. US Presidients\n"); printf("4. Quit\n"); printf(" Enter you choice:"); scanf(" %d", &choice2); if (choice2 ==1) { printf("\n\n World Series Champions of"); printf("the 1990's:\n"); printf("1990: Cincinatti 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 Yankess\n"); printf("\n\n\n"); break; } else if (choice2 == 2) { printf("\n\n Oscar winning Movies in "); printf(" the 1990's:\n"); printf("1990: Dances with Wolves\n"); printf("1991: The Silence of the Lambs\n"); printf("1992: Unforgiven\n"); printf("1993: Schindlers List\n"); printf("1994: ?\n"); printf("1995: ??\n"); printf("1996: The English Patient\n"); printf("1997: Titanic\n"); printf("1998: Shakespere in Love\n"); printf("1999: American Beauty\n"); printf("\n\n\n"); break; } else if (choice2 == 3) { printf("\n\nUS Presidents in the 1990's:\n"); printf("1990-1992: George Bush\n"); printf("1993-1999: Bill Clinton\n"); printf("\n\n\n"); break; } else if (choice2 == 4) { exit (1); } else { printf("Sorry, that is not a valid choice!\n"); break; } } // The section for when the user selects the 2000's case (3) : { printf("\n\nWhat 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("Enter your choice:"); scanf(" %d", &choice2); if (choice2 == 1) { printf("\n\nWorld series Champions of "); printf("The 2000's:\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"); printf("2006: St. Louis Cardinals\n"); printf("2007: Boston Red Sox\n"); printf("2008: Philadelphia Phillies\n"); printf("2009: New York Yankees\n"); printf("\n\n\n"); break; } else if (choice2 == 2) { printf("\n\nOscar winning movies in "); printf("the 2000's: \n"); printf("2000: Gladiator\n"); printf("2001: A Beautiful Mind\n"); printf("2002: Chicago\n"); printf("2003: The Lord of the Rings\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"); printf("\n\n\n"); break; } else if (choice2 == 3) { printf("\n\nUS Presidents in the 2000's\n"); printf("2000: Bill Clinton\n"); printf("2001-2008: George W Bush\n"); printf("2009: Barack Obama\n"); printf("\n\n\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("\n%d is not a valid choice.\n"); printf("Try again.\n"); break; } } while ((choice1 < 1) || (choice1 > 4)); return 0; }
What I have tried:
I have tried looking over the program and nothing obvious his coming up.
解决方案
这篇关于我收到一条评论“id返回1退出状态。我做错了什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!