- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想我已经尽力了,但是当我按选项传递3时,它总是显示为选项3。案例1,2,3按预期工作,但4,5,6,7,8,9, 10 将自动像情况 3 一样出现。那么您认为缺少什么?
#include "stdafx.h"
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <stdio.h>
using namespace std;
int pgk, ch1, ch2; // variables for the Menu1 and Menu2
char ch3; // Variable for menu 3
int main()
{
printf("1, Final Lab\n"); // first option
printf("2, Exit\n");// second option
cin >> ch1; // computer is going to scan the option from keyboard
// Switch change the option depending of the number we put in the keyboard
switch (ch1)
{
case 1:
{
goto Menu2; // if the user enters 1, it is going to send to send it to do the operations
}
case 2:
{
goto End; // if the user enters 2, it is going to end the program.
}
Menu2:
printf(" --------------------------Menu-------------------\n");
printf("1:Pounds to kilograms\n");
printf("2:inches to centimeters\n");
printf("3:cups to milliters\n");
printf("4:seconds to minutes \n");
printf("5:Knots to mph\n");
printf("6:tip calculator\n");
printf("7:Grade average\n");
printf("8:target heart rate calculator\n");
printf("9:discount calculator\n");
printf("10:end\n");
cin >> ch2; // enter the option the user wants
switch (ch2) // Options
{
case 1:
{
system("cls");
int pkg;
printf("Choose to convert pounds to kg or kg to pounds. Press 0 for 1st option and press any other number for 2nd option.\n");
scanf_s("%f", &pkg);
_asm
{
MOV EBX, pkg;
CMP pkg, 0;
JE pounds_kilos;
JMP kilos_pounds;
}
pounds_kilos:
float nguypounds, nguyconvert1, nguyanswer1;
nguyconvert1 = 2.204622f;
printf("Enter the amount of pounds you would like to convert to kilograms\n");
scanf_s("%f", &nguypounds);
_asm
{
FLD nguypounds;
FDIV nguyconvert1;
FST nguyanswer1;
}
printf("Your enter number of pounds to kilograms is %f\n", nguyanswer1);
system("pause");
goto Menu3;
kilos_pounds:
float nguykilos, nguyconvert2, nguyanswer2;
nguyconvert2 = 2.204622f;
printf("Enter the amount of kilograms you would like to convert to pounds\n");
scanf_s("%f", &nguykilos);
_asm
{
FLD nguykilos;
FMUL nguyconvert2;
FST nguyanswer2;
}
printf("Your enter number of kilograms to pounds is %f\n", nguyanswer2);
goto Menu3;
}
case 2: // if the user enters 2
{
system("cls");
int pkg;
printf("Choose to convert inches to centimeters or centimeters to inches. Press 0 for 1st option and press any other number for 2nd option.\n");
scanf_s("%f", &pkg);
_asm
{
MOV EBX, pkg;
CMP pkg, 0;
JE inches_centimeters;
JMP centimeters_inches;
}
inches_centimeters:
float nguyinches, nguyconvert3, nguyanswer3;
nguyconvert3 = 2.54f;
printf("Enter the amount of inches you would like to convert to centimeters\n");
scanf_s("%f", &nguyinches);
_asm
{
FLD nguyinches;
FMUL nguyconvert3;
FST nguyanswer3;
}
printf("Your enter number of inches to centimeters is %f\n", nguyanswer3);
goto Menu3;
}
centimeters_inches:
float nguycentimeters, nguyconvert4, nguyanswer4;
nguyconvert4 = 0.39370079f;
printf("Enter the amount of centimeters you like to convert to inches\n");
scanf_s("%f", &nguycentimeters);
_asm
{
FLD nguycentimeters;
FMUL nguyconvert4;
FST nguyanswer4;
}
printf("Your enter number of centimeters to inches is %f\n", nguyanswer4);
goto Menu3;
}
case 3: // if the user enter 3
{
system("cls");
int pkg;
printf("Choose to convert cups to milliters or milliters to cups. Press 0 for 1st option and press any other number for 2nd option.\n");
scanf_s("%f", &pkg);
_asm
{
MOV EBX, pkg;
CMP pkg, 0;
JE cups_milliters;
JMP milliters_cups;
}
cups_milliters:
float nguycups, nguyconvert5, nguyanswer5;
nguyconvert5 = 236.58823f;
printf("Enter the amount of cups you would like to convert to milliters\n");
scanf_s("%f", &nguycups);
_asm
{
FLD nguycups;
FMUL nguyconvert5;
FST nguyanswer5;
}
printf("Your enter number of cups to milliters is %f\n", nguyanswer5);
system("pause");
goto Menu3;
milliters_cups:
float nguymilliters, nguyconvert6, nguyanswer6;
nguyconvert6 = 236.58823f;
printf("Enter the amount of milliters you like to convert to cups\n");
scanf_s("%f", &nguymilliters);
_asm
{
FLD nguymilliters;
FDIV nguyconvert6;
FST nguyanswer6;
}
printf("Your enter number of milliters to cups is %f\n", nguyanswer6);
goto Menu3;
}
case 4: // if the user enters 4
{
system("cls");
int pkg;
printf("Choose to convert seconds to minutes or minutes to seconds. Press 0 for 1st option and press any other number for 2nd option.\n");
scanf_s("%f", &pkg);
_asm
{
MOV EBX, pkg;
CMP pkg, 0;
JE sec_min;
JMP min_sec;
}
sec_min:
float nguyseconds, nguyconvert7, nguyanswer7;
nguyconvert7 = 60;
printf("Enter the amount of seconds you would like to convert to minutes\n");
scanf_s("%f", &nguyseconds);
_asm
{
FLD nguyseconds;
FDIV nguyconvert7;
FST nguyanswer7;
}
printf("Your enter number of seconds to minutes is %f\n", nguyanswer7);
goto Menu3;
min_sec:
float nguyminutes, nguyconvert8, nguyanswer8;
nguyconvert8 = 60;
printf("Enter the amount of minutes you like to convert to seconds\n");
scanf_s("%f", &nguyminutes);
_asm
{
FLD nguyminutes;
FMUL nguyconvert8;
FST nguyanswer8;
}
printf("Your enter number of minutes to seconds is %f\n", nguyanswer8);
system("pause");
goto Menu3;
}
case 5:
{
system("cls");
int pkg;
printf("Choose to knots to mph or mph to knots. P=ress 0 for 1st option and press any other number for 2nd option.\n");
scanf_s("%f", &pkg);
_asm
{
MOV EBX, pkg;
CMP pkg, 0;
JE knots_mph;
JMP mph_knots;
}
knots_mph:
float nguyknots, nguyconvert9, nguyanswer9;
nguyconvert9 = 1.15f;
printf("Enter the amount of knots you would like to convert to mph\n");
scanf_s("%f", &nguyknots);
_asm
{
FLD nguyknots;
FMUL nguyconvert9;
FST nguyanswer9;
}
printf("Your enter number of knots to mph is %f\n", nguyanswer9);
goto Menu3;
mph_knots:
float nguymph, nguyconvert10, nguyanswer10;
nguyconvert10 = 1.15f;
printf("Enter the amount of mph you like to convert to knots\n");
scanf_s("%f", &nguymph);
_asm
{
FLD nguymph;
FDIV nguyconvert10;
FST nguyanswer10;
}
printf("Your enter number of minutes to seconds is %f\n", nguyanswer10);
system("pause");
goto Menu3;
}
case 6:
{
system("cls");
float nguybill, nguytip, nguyamount;
printf("Please enter the total amount of your bill\n");
scanf_s("%f", &nguybill);
printf("Now add the percentage you would like to tip. PLEASE ENTER IN PERCENTAGE IN DECIMAL FORM!\n");
scanf_s("%f", &nguytip);
_asm
{
fld nguybill
fld nguytip
fmul nguybill
fadd st(0), st(1)
fst nguyamount
}
printf("the the toal amount after tip is %f\n", nguyamount);
goto Menu3;
}
case 7:
{
system("cls");
float nguytest1, nguytest2, nguytest3, nguyave, nguytotave;
nguyave = 3;
printf("Please enter the grade of your first test.\n");
scanf_s("%f", &nguytest1);
printf("Please enter the grade of your second test.\n");
scanf_s("%f", &nguytest2);
printf("Please enter the grade of your thrid test.\n");
scanf_s("%f", &nguytest3);
_asm
{
fld nguytest1
fld nguytest2
fld nguytest3
fadd st(0), st(1)
fadd st(0), st(2)
fdiv nguyave
fst nguytotave
}
printf("Your average grade is %f", nguytotave);
goto Menu3;
}
case 8:
{
system("cls");
float nguyage, nguyageconst, nguymaxhr, nguytarghr, nguymulmax;
nguyageconst = 220;
nguymulmax = .70f;
printf("Please enter the total amount of your age to find your max heart rate and target heart rate\n");
scanf_s("%f", &nguyage);
_asm
{
fld nguyage
fld nguyageconst
fsub nguyage
fst nguymaxhr
}
_asm
{
fld nguymaxhr
fmul nguymulmax
fst nguytarghr
}
printf("your max heart rate should be %f beat per minute\n", nguymaxhr);
printf("and your target heart rate should be %f beats per minute\n", nguytarghr);
goto Menu3;
}
case 9:
{
system("cls");
float nguyogprice, nguydis, nguyoff, nguynamount;
printf("Please enter the oringal price\n");
scanf_s("%f", &nguyogprice);
printf("Now enter the given discout. PLEASE ENTER IN PERCENTAGE IN DECIMAL FORM!\n");
scanf_s("%f", &nguydis);
_asm
{
fld nguyogprice
fld nguydis
fmul nguyogprice
fst nguyoff
}
_asm
{
fld nguyoff
fld nguyogprice
fsub st(0), st(1)
fst nguynamount
}
printf("The new sale price is %f\n", nguynamount);
goto Menu3;
}
case 10: // if the user enters 5
{
goto End; //go to end
}
}
Menu3: // This menu is going to ask if the user wants to continue the program
printf(" -------------------------Question---------------------\n"); // display message
printf("Do you want to continue the program Y/N\n"); // display message
cin >> ch3; // enter yes or no
switch (ch3) // conditional
{
case 'y': // if the user enters 'y'
{
goto Menu2; // go to menu 2 and continue the program
}
case 'Y': // if the user enters 'Y'
{
goto Menu2; // go to menu 2 and continue the program
}
case 'n': // if the user enters 'n'
{
goto End; // finish the program
}
case 'N': // if the user enters 'N'
{
goto End; // finish the program
}
}
End: // menu to end the program
system("pause"); // pause the system
return 0;// end program
}
最佳答案
在 case 3
之前的右大括号被错误地放置在那里,它关闭了 switch 语句。因此输入 3 到 9 都以情况 3 结束。
无意冒犯,但由于可维护性和效率较差(编译器的优化机会),在非常特定的上下文之外使用 goto 长期以来一直被认为是极其糟糕的编程实践。投入时间和精力来理清代码和重组程序将会得到返回。
关于c++ - Switch case 程序在某个点不断循环。想不通,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37372129/
我经常在 ATS 中看到使用 case、case+ 或 case- 形成的 case 表达式。有什么区别? 最佳答案 如果表达式不详尽,使用 case 会发出警告,case+ 会产生错误,而 case
我有一个导入时全部大写的表,我想将其转换为正确的大小写。你们用什么脚本来完成这个? 最佳答案 这个函数: “正确大小写”由空格分隔的所有“大写”单词 保留“小写单词” 即使对于非英语字母也能正常工作
#include int main() { switch(2) { case 1: if(1)
我已经四处寻找了一段时间,如果我使用的术语不当,请原谅我... 代码的目标是在输入为 0 时更新 Aout1 和 Aout0,输出对应于 7 段显示,但出现以下错误: “错误 (10170):Four
我正在尝试按照 PostgreSQL 手册中的说明进行操作。 PostgreSQL: Documentation: 9.1: Control Structures 我的 PostgreSQL 服务器是
我有一个状态机,其中有几个非常相似的状态。我可以为每个状态编写它,如下例所示: module CHECK_FSM ( GO, DONE, CLK, RESETN ); input GO;
如何使用或创建案例? 就像是: string str; case (str) "abc" || "dfg": begin //some code end "yfg":
这个问题已经有答案了: Are double and single quotes interchangeable in JavaScript? (23 个回答) 已关闭 9 年前。 我正在学习Java
汽车 Make | Model | Year | Color Honda | Accord | 12 | Red Lexus | IS | 14 |
如何使用当前 case 语句的值跳转到 switch-case 条件下的另一个 case 语句? 是否可以使用 switch case 来实现这种事情,或者是否有其他实现方式? 有可能实现吗?如果没有
我理解下面的代码。 var day = 2; switch (day) { case 1: document.write("Monday"); break;
这是有效的。 object FilesToDFDS { case class Student(id: Int, name: String, dept:String) def main(
我对 VHDL 还是个新手。我需要在 CASE 语句中为多个信号赋值,如下所示: CASE input24 IS WHEN "00" THEN output0
我有这个 case 语句,它给出了一个错误“变量 constant1 未使用”。它似乎忽略了变量并返回了第一行,因此变量显然没有范围。如果我用数字 1 替换常量,那么它就可以工作。在 Elixir 中
在 MySQL 中,是否可以在 SELECT 子句中有两个 CASE 语句,其中第二个 CASE 语句依赖于第一个 CASE 语句? 例如,考虑以下查询: SELECT CASE WHEN `user
我正在尝试一个挑战,我需要获得一个随机数,并在没有重复的情况下打印数字内的数字总和:例如,123 将打印 6 ( 1 + 2 + 3 ),而 32111 将做同样的事情(因为我们没有在我们的总和中添加
当有人试图更新当前未存储在我的散列中的值时,我想立即返回 when 'add' 而无需重新启动整个 case声明,因为我已经知道他们想要添加并且不想再次提示他们。 有没有一种方法可以在不重新启动整个案
老 C 程序员可以在 Swift 方面得到一些帮助。 我不太了解 if-case 语法。例如: if case 20...30 = age { print ("in range.") } cas
老 C 程序员可以在 Swift 方面得到一些帮助。 我不太了解 if-case 语法。例如: if case 20...30 = age { print ("in range.") } cas
我有一个 ArrayList,其中包含以下字符串:[name, age, gender, salary] . 有没有办法可以将 ArrayList 中的值用作 case 表达式? 显而易见的答案是否定
我是一名优秀的程序员,十分优秀!