且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

开关盒故障

更新时间:2022-10-16 13:03:23



YitzHandel写道:
以下是我程序的摘录,我是分离出来并编译为自己的程序。

问题是,只要案例测试成立,下面的所有案例都会执行。因此,如果用户输入4,将执行来自案例4-9的语句。

(我用cout替换函数调用进行测试。)

我我正在使用Win2k,Open Watcom IDE v 1.3。

这已经在程序的几个地方进行了测试。

(ps - 它按原样编译,它也很好地编译所有
注释掉的库 - 无论哪种方式都出现错误)

//#include< stdio.h>
#include< stdlib.h>
#include< iostream.h> //而不是使用命名空间std
// #include< string.hpp>
// #include< fstream.h>
// #include< istream>
// #include" Fcopy.h"
// #include< ctime>
// #include< math.h>

int main()
{menu_select_int = -1;


{
系统(CLS);
cout<<" ; ********************** MENU ********************* ** \ n ;;
cout<< &QUOT;创建或编辑输入文件.......... 1 \ n&quot ;;
cout<< &QUOT;计算器。没有。阶段................ 2 \ n&quot ;;
cout<< &QUOT;数据图.......................... 3 \ n&quot ;;
cout<< &QUOT; RR与阶段数相对............... 4 \ n&quot ;;
cout<< &QUOT; McCabe Thiele情节................. 5 \ n&quot ;;
cout<< &QUOT;打印输入文件............ 6 \ n&quot ;;
cout<< &QUOT;托盘组合物的打印输出.7 \ n&quot ;;
cout<< &QUOT; vle数据的打印输出........... 8 \ n&quot ;;
cout<< &QUOT;退出............................... 9 \ n&quot ;;
cout<< &QUOT; ********** * \ n \ n&quot ;;
cout<< MENU:&quot ;;
cin>> menu_select_int;

开关(menu_select_int)
{/>
案例1:
cout<< 输入数据函数\ n;&#;> cout<< case 1;
cin.ignore();




添加break在每个案例之后你都不想要

来说明下一个案例...


-David


优异。有效。谢谢。




YitzHandel写道:
以下是我程序的摘录,我把它分开并编译成自己的程序。

问题是,一旦案例测试成立,下面的所有案例都会执行。因此,如果用户输入4,将执行来自案例4-9的陈述。



[snip]


你需要在每个案例body之后插入break语句。默认情况下

(不幸的是),switch语句会失效。这是一个例子:


开关(some_int)

{

案例1:

cout<< 案例1 &LT;&LT;结束;

休息;

案例2:

cout<< 案例2 &LT;&LT;结束;

休息;

默认值:

cout<< 默认情况 &LT;&LT;结束;

}


干杯! --M


The following is an extract from my program, which I seperated out and
compiled as its own program.

The problem is that as soon as a case tests true, all the cases below
it execute as well. So if the user inputs, 4, the statements from
cases 4-9 will execute.

(I replaced function calls with cout for testing.)

I am using Win2k, Open Watcom IDE v 1.3.

This has tested as happening in several places in the program.

(p.s. - it compiles as is, it also compliles fine with all the
commented out libraries - same error either way)


//#include <stdio.h>
#include <stdlib.h>
#include <iostream.h> // instead of using namespace std
//#include <string.hpp>
//#include <fstream.h>
//#include <istream>
//#include "Fcopy.h"
//#include <ctime>
//#include <math.h>
int main ()
{
int menu_select_int =-1;

do
{
system("CLS");
cout <<"**********************MENU********************* **\n";
cout << " Create Or Edit Input File..........1\n";
cout << " Calc. no. of stages................2\n";
cout << " Data plot..........................3\n";
cout << " RR vs. No. Of stages...............4\n";
cout << " McCabe Thiele plot.................5\n";
cout << " Printout the input file............6\n";
cout << " Printout of the tray compositions..7\n";
cout << " Printout of the vle data...........8\n";
cout << " Quit...............................9\n";
cout << "************************************************* \n\n";
cout << "MENU: ";
cin >> menu_select_int;

switch (menu_select_int)
{

case 1:
cout << "\ngoing to input data function\n";
cout << "case 1";
cin.ignore();

case 2:
cout << "\ngoing to CNOS function\n";
cout << "case 2";
cin.ignore();

case 3:
cout << "\ngoing to DP function\n";
cout << "case 3";
cin.ignore();

case 4:
cout << "\ngoing to RR vs function\n";
cout << "case 4";
cin.ignore();

case 5:
cout << "\ngoing to McTh function\n";
cout << "case 5";
cin.ignore();

case 6:
cout << "\ngoing to PIF function\n";
cout << "case 6";
cin.ignore();

case 7:
cout << "\ngoing to printout function\n";
cout << "case 7";
cin.ignore();

case 8:
cout << "\ngoing to PO VLE function\n";
cout << "case 8";
cin.ignore();

case 9:
cout << "\ngoing to AYS - end function\n";
cout << "case 9";
cin.ignore();
} //end switch case
} while (menu_select_int != 9);

cin.ignore();
return(0);

}


YitzHandel wrote:
The following is an extract from my program, which I seperated out and
compiled as its own program.

The problem is that as soon as a case tests true, all the cases below
it execute as well. So if the user inputs, 4, the statements from
cases 4-9 will execute.

(I replaced function calls with cout for testing.)

I am using Win2k, Open Watcom IDE v 1.3.

This has tested as happening in several places in the program.

(p.s. - it compiles as is, it also compliles fine with all the
commented out libraries - same error either way)


//#include <stdio.h>
#include <stdlib.h>
#include <iostream.h> // instead of using namespace std
//#include <string.hpp>
//#include <fstream.h>
//#include <istream>
//#include "Fcopy.h"
//#include <ctime>
//#include <math.h>
int main ()
{
int menu_select_int =-1;

do
{
system("CLS");
cout <<"**********************MENU********************* **\n";
cout << " Create Or Edit Input File..........1\n";
cout << " Calc. no. of stages................2\n";
cout << " Data plot..........................3\n";
cout << " RR vs. No. Of stages...............4\n";
cout << " McCabe Thiele plot.................5\n";
cout << " Printout the input file............6\n";
cout << " Printout of the tray compositions..7\n";
cout << " Printout of the vle data...........8\n";
cout << " Quit...............................9\n";
cout << "************************************************* \n\n";
cout << "MENU: ";
cin >> menu_select_int;

switch (menu_select_int)
{

case 1:
cout << "\ngoing to input data function\n";
cout << "case 1";
cin.ignore();



Add a "break" statement after every case you don''t want
to fall through to the next case...

-David


excellent. that worked. thanks.



YitzHandel wrote:
The following is an extract from my program, which I seperated out and
compiled as its own program.

The problem is that as soon as a case tests true, all the cases below
it execute as well. So if the user inputs, 4, the statements from
cases 4-9 will execute.


[snip]

You need to insert break statements after each case "body". By default
(unfortunately), switch statements fall through. Here''s an example:

switch( some_int )
{
case 1:
cout << "Case 1" << endl;
break;
case 2:
cout << "Case 2" << endl;
break;
default:
cout << "Default case" << endl;
}

Cheers! --M