请帮忙 !这很紧急 。下面给出的代码没有显示if条件的输出。请帮我解决问题! [英] Please help ! it's urgent . The code given below is not showing the output for if conditions . Please help me to resolve the problem!

查看:49
本文介绍了请帮忙 !这很紧急 。下面给出的代码没有显示if条件的输出。请帮我解决问题!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  #include   <   iostream.h  >  
#include < conio.h >
#include < stdio.h >
#include < dos.h >
void main()
{
clrscr();
int x;
x = 0 ;
char ch1 [ 100 ],ch2,ch3,ch4,ch5,ch6,ch7, ch8,ch9,ch10,ch11;
cout<< \ n \ nn \ n \ n \ n欢迎!!! \ n\ n;
cout<< \ n\t\t请输入您的姓名:;
得到(ch1);
cout<< \ n \ n \\\\\加载.... 。;
延迟( 2000 );
{clrscr();
cout<< \ n \ nn \ n \嗨;
puts(ch1);
cout<< \ n \ n \ t在开始之前,请完成规则测验!;
cout<< \ n \ n \ t请稍等......< /跨度>;
延迟( 2000 );
}
{clrscr();
cout<< \ n \ nn \ n \\\\\\\\\\\\\\\\\\\\ - \ n \ n \\ n \\ n;
延迟( 2000 );
cout<< 1)问题是多项选择题。\ n \ n \吨;
延迟( 3000 );
cout<< 2)每个问题只有一个正确的选项。\ nn n\t;
延迟( 3000 );
cout<< 3)以'a','b','的形式输入答案c'或'd'only.\\\
\\\
\t
;
延迟( 3000 );
cout<< 4)每个正确答案将获得10分。\ n \ n\t;
延迟( 3000 );
cout<< 5)错误答案不会推断出任何积分。\ n \\ nn \t\t\t\t\t;
延迟( 2000 );
cout<< 享受QUIZ!...;
延迟( 2000 );
{clrscr();
cout<< \ n \ nn \ n;
cout<< \t\t Q1:RAM位于何处?\ nn \
;
cout<< \t\ta)扩展板\ n \\ n \ n t\tb)外部驱动器\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ;
XX:cin>> ch2;
if (ch2 == ' c'
{x = x + 10 ;
cout<< \ n \ nn \ tt \ t绝对正确!\你的分数是:<< x<< \\\
\\\
;
}
else
{ if ((ch2 == < span class =code-string>'
a')||(ch2 == ' b')||(ch2 == ' d'))
cout<< \ n \ n \ t哎呀!错误的答案。正确答案是c)母板。\ n \\ n;
else
{cout<< \ n \ n \\\\\无效选项!!! \ n \ n \\\\\\ n请输入有效选项(a,b,c,d)。\ n \\\\\\;
goto XX;
}
}
{clrscr();
cout<< \ n \ n \\\\\\\\\\\\\\\\\\\\\\发明者:\ n \ n;
cout<< \ t \ t)Oracle \ nn \ n \ t \ tb)微软公司(纽约公司)对于他们来说,太阳了,不知道其他人。 ;
YY:cin>> ch3;
if (ch3 == ' d'
{x = x + 10 ;
cout<< \ n \ n \\\\ Good Job!\你的分数是:<< x<< \\\
\\\
;
}
其他
{如果((ch3 == < span class =code-string>'
a')||(ch3 == ' b')||(ch3 == ' c'))
cout<< \ n \ n \ t \t抱歉错误答案!\ n \\ n \ n \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
else
{cout<< \ n \ n \\\\\无效选项!!! \ n \ n \\\\\\ n请输入有效选项(a,b,c,d)。\ n \\\\\\;
goto YY;
}
}
{clrscr();
cout<< \ n \ nn \ tt:Q3:印度的第一个超级电脑是:\ n \ n;
cout<< \ t \ t)Agni \ nn \ n \ t \ tb)流动解决方案\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ >;
ZZ:cin>> ch4;
if (ch4 == ' c'
{x = x + 10 ;
cout<< \ n \ n \\\\\ Aw真棒!\ n \ n \\\ t \ t你的分数是:<< x<< \\\
\\\
;
}
else
{ if ((ch4 == < span class =code-string>'
a')||(ch4 == ' b')||(ch4 == ' d'))
cout<< \ n \ n \ t哎呀!你错了。正确的答案是c)Param.\\\
.n
;
else
{cout<< \ n \ n \\\\\无效选项!!! \ n \ n \\\\\\ n请输入有效选项(a,b,c,d)。\ n \\\\\\;
goto ZZ;
}
}
{clrscr();
cout<< \ n \ nn \ tt:Q4:ROM组成of:\ n \ n;
cout<< \ t\ta)软盘\ nn \ n t \ tb)磁芯\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ /跨度>;
AA:cin>> ch5;
if (ch5 == ' d'
{x = x + 10 ;
cout<< \ n \ n \\\\ Great Job!\你的分数是:<< x<< \\\
\\\
;
}
其他
{如果((ch5 == < span class =code-string>'
a')||(ch5 == ' b')||(ch5 == ' c'))
cout<< \ n \ n \ t \t抱歉错误答案!正确的答案是d)光电电池。\ n \\ n;
else
{cout<< \ n\\\
\t\t无效选项!!! \ n\\\
\t\t请输入有效的选项(a,b,c,d)。\ n \\\\\\
;
goto AA;
}
}
{clrscr();
cout<< \ n \ nn \ tt:Q5:字长计算机的测量结果如下:\ n \ n;
cout<< \ t \ t)Bits \ n \ n \ t \tb)Bytes \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ;
BB:cin>> ch6;
if (ch6 == ' b'
{x = x + 10 ;
cout<< \ n做得好!\ n你的分数是:<< x<< \ n \ n;
}
else
{ if ((ch6 == < span class =code-string>'
a')||(ch6 == ' c')||(ch6 == ' d'))
cout<< \ n \ n \ t哎哟!这是错的!\ n \\ n \ n \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
else
{cout<< \ n \ n \\\\\无效选项!!! \ n \ n \\\\\\ n请输入有效选项(a,b,c,d)。\ n \\\\\\;
goto BB;
}
}
{clrscr();
cout<< \ n \ n \\\\\\\\\\\\\\\\\\\\\\\\\\\\他们自己:\ n \ n;
cout<< \ t \ t)高级语言\ n \ n \\ t \\ t \\ t \\ t \\ t \\ t \\ t \\ t \\ t \\ t \\ t \\ t \\ t \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n跨度>;
CC:cin>> ch7;
if (ch7 == ' d'
{x = x + 10 ;
cout<< \ n \ n \\\\\ Aw真棒!\ n \ n \\\ t \ t你的分数是:<< x<< \\\
\\\
;
}
else
{ if ((ch7 == < span class =code-string>'
a')||(ch7 == ' b')||(ch7 == ' c'))
cout<< \ n \ n \ t \t错误的回答!\ n \ n \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
else
{cout<< \ n \ n \\\\\无效选项!!! \ n \ n \\\\\\ n请输入有效选项(a,b,c,d)。\ n \\\\\\;
goto CC;
}
}
{clrscr();
cout<< \ n \ nn \ tt:Q7:谁被考虑作为人工智能之父?\ n \\ n;
cout<< \t\ta)Alan Turing \ n \ n \约翰·麦卡锡(John McColey),乔治·布尔(George Boole),艾伦·纽厄尔(Allen Newell),他妈的 ;
DD:cin>> ch8;
if (ch8 == ' b'
{x = x + 10 ;
cout<< \ n \ n \\\\ Great Job!\你的分数是:<< x<< \\\
\\\
;
}
else
{ if ((ch8 == < span class =code-string>'
a')||(ch8 == ' c')||(ch8 == ' d'))
cout<< \ n \ n \ t \t抱歉错误答案!\ n \ n \\ n \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
else
{cout<< \ n \ n \\\\\无效选项!!! \ n \ n \\\\\\ n请输入有效选项(a,b,c,d)。\ n \\\\\\;
goto DD;
}
}
{clrscr();
cout<< \ n \ nn \ tt:Q8:CD ROM是a / an:\ n\\\
;
cout<< \ t \ t)光学设备\ n \ n \ t \ tb)磁性装置\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ;
EE:cin>> ch9;
if (ch9 == ' c'
{x = x + 10 ;
cout<< \ n \ nn \ tt \t很棒!\ n \ n \\\ t \ t你的分数是:<< x<< \\\
\\\
;
}
else
{ if ((ch9 == < span class =code-string>'
a')||(ch9 == ' b')||(ch9 == ' d'))
cout<< \ n \ n \ t哎哟!你错了!\ n \\ n \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
else
{cout<< \ n \ n \\\\\无效选项!!! \ n \ n \\\\\\ n请输入有效选项(a,b,c,d)。\ n \\\\\\;
goto EE;
}
}
{clrscr();
cout<< \ n \ nn \ tt:Q9:谁是谁Bing的创始人?\ n \ n;
cout<< \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\大卫·费罗(Jeno Yang)没有以上任何人都没有这样的事情。不管怎样。 t;
FF:cin>> ch10;
if (ch10 == ' a'
{x = x + 10 ;
cout<< \ n \ n \\\\\t绝对正确!\你的分数是:<< x<< \\\
\\\
;
}
else
{ if ((ch10 == < span class =code-string>'
b')||(ch10 == ' c')||(ch10 == ' d'))
cout<< \ n \ n \ t \t错误答案!\ n \ n \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
else
{cout<< \ n \ n \\\\\无效选项!!! \ n \ n \\\\\\ n请输入有效选项(a,b,c,d)。\ n \\\\\\;
goto FF;
}
}
{clrscr();
cout<< \ n \ n \\\\\\\\\\\\\\\\\谷歌的创始人?\ n \ n;
cout<< \ t \ ta)Larry Page& Sergey Brin \ nn Jawed Karim& Chad Hurley's \\ n n n n t t t))))))))))))))))))))))))))))))))))))))))))J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J ;史蒂夫鲍尔默的心情; ;
GG:cin>> ch11;
if (ch11 == ' a'
{x = x + 10 ;
cout<< \ n \ n \\\\\\\\\\\\\\\\\你的分数是:<< x<< \\\
\\\
;
}
else
{ if ((ch11 == < span class =code-string>'
b')||(ch11 == ' c')||(ch11 == ' d'))
cout<< \ n \ n \ t \t抱歉错误的回答!\ n \ n \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
else
{cout<< \ n\\\
\t\t无效的opiton !!! \ n\\\
\t\t请输入有效选项(a,b,c,d)。\ n \\\\\\
;
goto GG;
}
}
{clrscr();
cout<< \ n \ nn \ n \ tt !;
cout<< \ n \ n \\\\\这里是结果< /跨度>;
cout<< \ n \ nn \ n \\\\\\加载;
延迟( 1000 );
cout<< ;
延迟( 1000 );
cout<< ;
延迟( 1000 );
cout<< ;
延迟( 1000 );
cout<< ;
延迟( 2000 );
if ((x == 100 )||(x == 90 )||(x == 80 ))
{cout<< \ n \ n \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\坚持下去!\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
}
else
{ if ((x == < span class =code-digit> 70
)||(x == 60 )||(x == 50 ))
cout<< \ n \ nn好的工作!\ n \\\你可以做得更好。你的分数是:<< x;
else
{ if ((x == 40 )||(x == 30 ))
cout<< \ n \ n \\\\\你是平均水平!下次好运!\ n \\ t \t您的总分是:<< x;
else
cout<< \ n \ n \\\\\ not not good !!! !!! \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}





我尝试过的事情:



下面给出的所有问题部分都没有显示任何输出!

  if (ch5 == '  d'
{x = x + 10 ;
cout<< \ n \ n \\\\ Great Job!\你的分数是:<< x<< \\\
\\\
;
}
其他
{如果((ch5 == < span class =code-string>'
a')||(ch5 == ' b')||(ch5 == ' c'))
cout<< \ n \ n \ t \t抱歉错误答案!正确的答案是d)光电电池。\ n \\ n;
else
{cout<< \ n\\\
\t\t无效选项!!! \ n\\\
\t\t请输入有效的选项(a,b,c,d)。\ n \\\\\\
;
goto AA;
}
}

解决方案

1)这并不紧急。这对你来说很紧迫,因为你已经拖延了并且把它放得太晚了。

2)它的缩进很严重,因此很难阅读并弄清楚发生了什么。

3)它充满了 goto 语句,这使得更难以弄清楚发生了什么。

4)我们可以'为你解决它,因为我们不知道它应该做什么,或者你提供什么输入来使它导致问题。请记住,我们无法访问您的作业问题,更不用说您的硬盘或屏幕...

5)让您的代码正常工作是您的任务的一部分!



所以,它取决于你。

幸运的是,你有一个工具可以帮助你找到正在发生的事情:调试器。你如何使用它取决于你的编译器系统,但是一个快速的谷歌用于你的IDE名称和调试器应该给你你需要的信息。



放一个断点在函数的第一行,并通过调试器运行代码。然后查看您的代码,并查看您的数据并找出手动应该发生的事情。然后单步执行每一行检查您预期发生的情况正是如此。如果不是,那就是当你遇到问题时,你可以回溯(或者再次运行并仔细观察)以找出原因。


对不起,但我们不能为你做到这一点 - 时间让你学习一门新的(非常非常有用的)技能:调试!


Griff是正确的goto正在制作代码不可读。为你有问题的ch5做一些输出,看看发生了什么。



尝试消除 ALL goto语句并使用subfuctions来获得更干净的代码。



我只会写:

 cin>> CH5; 


#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<dos.h>
void main()
{
  clrscr();
  int x;
  x = 0;
  char ch1[100] , ch2 , ch3 , ch4 , ch5 , ch6 , ch7 , ch8 , ch9 , ch10 , ch11;
  cout<<"\n\n\n\n\n\t\t WELCOME !!!\n\n";
  cout<<"\n\t\t Please enter your name : ";
  gets(ch1);
  cout<<"\n\n\t\t LOADING ..... ";
  delay(2000);
  { clrscr();
    cout<<"\n\n\n\t Hi ";
    puts(ch1);
    cout<<"\n\n\t Just go through the rules before beginning the QUIZ !";
    cout<<"\n\n\t Please wait ....";
    delay(2000);
  }
  { clrscr();
    cout<<"\n\n\n\t\t RULES :- \n\n\t";
    delay(2000);
    cout<<" 1) The questions are multiple choice questions.\n\n\t";
    delay(3000);
    cout<<" 2) There is only one correct option to every question.\n\n\t";
    delay(3000);
    cout<<" 3) Enter answer in the form of 'a' , 'b' , 'c' or 'd' only.\n\n\t";
    delay(3000);
    cout<<" 4) 10 points will be awarded for every correct answer.\n\n\t";
    delay(3000);
    cout<<" 5) No points will be deduced for wrong answer.\n\n\t\t\t\t\t";
    delay(2000);
    cout<<" Enjoy the QUIZ !...";
    delay(2000);
    { clrscr();
      cout<<"\n\n\n";
      cout<<"\t\t Q1: Where is RAM located ?\n\n";
      cout<<"\t\t a) Expansion Board\n\n\t\t b) External Drive\n\n\t\t c) Mother Board\n\n\t\t d) All of above\n\n\t\t ";
   XX:cin>>ch2;
      if(ch2=='c')
      { x = x + 10;
	cout<<"\n\n\t\t Absolutely Correct !\n\n\t\t Your score is: "<<x<<"\n\n";
      }
      else
      { if((ch2=='a')||(ch2=='b')||(ch2=='d'))
	cout<<"\n\n\t\t Oops ! Wrong answer.\n\n\t\t The correct answer is c) Mother Board.\n\n";
	else
	{ cout<<"\n\n\t\t Invalid option !!!\n\n\t\t Please enter a valid option (a,b,c,d).\n\n\t\t ";
	  goto XX;
	}
      }
      { clrscr();
	cout<<"\n\n\t\t Q2: Java was originally invented by : \n\n";
	cout<<"\t\t a) Oracle\n\n\t\t b) Microsoft\n\n\t\t c) Novell\n\n\t\t d) Sun\n\n\t\t ";
     YY:cin>>ch3;
	if(ch3=='d')
	{ x = x + 10;
	  cout<<"\n\n\t\t Good Job !\n\n\t\t Your score is : "<<x<<"\n\n";
	}
	else
	{ if((ch3=='a')||(ch3=='b')||(ch3=='c'))
	  cout<<"\n\n\t\t Sorry wrong answer !\n\n\t\t The correct answer is d) Sun.\n\n";
	  else
	  { cout<<"\n\n\t\t Invalid option !!!\n\n\t\t Please enter a valid option (a,b,c,d).\n\n\t\t ";
	    goto YY;
	  }
	}
	{ clrscr();
	  cout<<"\n\n\t\t Q3: India's first super computer is : \n\n";
	  cout<<"\t\t a) Agni\n\n\t\t b) Flow solver\n\n\t\t c) Param\n\n\t\t d) Trisul\n\n\t\t ";
       ZZ:cin>>ch4;
	  if(ch4=='c')
	  { x = x + 10;
	    cout<<"\n\n\t\t Awesome !\n\n\t\t Your score is : "<<x<<"\n\n";
	  }
	  else
	  { if((ch4=='a')||(ch4=='b')||(ch4=='d'))
	    cout<<"\n\n\t\t Oops ! You are wrong.\n\n\t\t The correct answer is c) Param.\n\n";
	    else
	    { cout<<"\n\n\t\t Invalid option !!!\n\n\t\t Please enter a valid option (a,b,c,d).\n\n\t\t ";
	      goto ZZ;
	    }
	  }
	  { clrscr();
	    cout<<"\n\n\t\t Q4: ROM is composed of : \n\n";
	    cout<<"\t\t a) Floppy Disk\n\n\t\t b) Magnetic cores\n\n\t\t c) Microprocessors\n\n\t\t d) Photoelectric cells\n\n\t\t ";
	 AA:cin>>ch5;
	    if(ch5=='d')
	    { x = x + 10;
	      cout<<"\n\n\t\t Great Job !\n\n\t\t Your score is : "<<x<<"\n\n";
	    }
	    else
	    { if((ch5=='a')||(ch5=='b')||(ch5=='c'))
	      cout<<"\n\n\t\t Sorry wrong answer !\n\n\t\t The correct answer is d) Photoelectric cells.\n\n";
	      else
	      { cout<<"\n\n\t\t Invalid option !!!\n\n\t\t Please enter a valid opition (a,b,c,d).\n\n\t\t ";
		goto AA;
	      }
	    }
	    { clrscr();
	      cout<<"\n\n\t\t Q5: The word length of a computer is measured in : \n\n";
	      cout<<"\t\t a) Bits\n\n\t\t b) Bytes\n\n\t\t c) Millimetres\n\n\t\t d) Metres\n\n\t\t ";
	   BB:cin>>ch6;
	      if(ch6=='b')
	      { x = x + 10;
		cout<<"\n Well Done !\n Your score is : "<<x<<"\n\n";
	      }
	      else
	      { if((ch6=='a')||(ch6=='c')||(ch6=='d'))
		cout<<"\n\n\t\t Oops ! This is wrong !\n\n\t\t The correct answer is b) Bytes.\n\n";
		else
		{ cout<<"\n\n\t\t Invalid option !!!\n\n\t\t Please enter a valid option (a,b,c,d).\n\n\t\t ";
		  goto BB;
		}
	      }
	      { clrscr();
		cout<<"\n\n\t\t Q6: Compiliers and Interpreters are themselves : \n\n";
		cout<<"\t\t a) High Level Language\n\n\t\t b) Codes\n\n\t\t c) Mnemonics\n\n\t\t d) Programs\n\n\t\t ";
	     CC:cin>>ch7;
		if(ch7=='d')
		{ x = x + 10;
		  cout<<"\n\n\t\t Awesome !\n\n\t\t Your score is : "<<x<<"\n\n";
		}
		else
		{ if((ch7=='a')||(ch7=='b')||(ch7=='c'))
		  cout<<"\n\n\t\t Wrong answer !\n\n\t\t The correct answer is d) Programs\n\n";
		  else
		  { cout<<"\n\n\t\t Invalid option !!!\n\n\t\t Please enter a valid option (a,b,c,d).\n\n\t\t ";
		    goto CC;
		  }
		}
		{ clrscr();
		  cout<<"\n\n\t\t Q7: Who is considered as The Father of Artificial Intelligence ?\n\n";
		  cout<<"\t\t a) Alan Turing\n\n\t\t b) John McCarthy\n\n\t\t c) George Boole\n\n\t\t d) Allen Newell\n\n\t\t ";
	       DD:cin>>ch8;
		  if(ch8=='b')
		  { x = x + 10;
		    cout<<"\n\n\t\t Great Job !\n\n\t\t Your score is : "<<x<<"\n\n";
		  }
		  else
		  { if((ch8=='a')||(ch8=='c')||(ch8=='d'))
		    cout<<"\n\n\t\t Sorry wrong answer !\n\n\t\t The correct answer is b) John McCarthy.\n\n";
		    else
		    { cout<<"\n\n\t\t Invalid option !!!\n\n\t\t Please enter a valid option (a,b,c,d).\n\n\t\t ";
		      goto DD;
		    }
		  }
		  { clrscr();
		    cout<<"\n\n\t\t Q8: CD ROM is a/an : \n\n";
		    cout<<"\t\t a) Optical device\n\n\t\t b) Magnetic device\n\n\t\t c) Electro Magnetic device\n\n\t\t d) Mechanical device\n\n\t\t ";
		 EE:cin>>ch9;
		    if(ch9=='c')
		    { x = x + 10;
		      cout<<"\n\n\t\t Brilliant !\n\n\t\t Your score is : "<<x<<"\n\n";
		    }
		    else
		    { if((ch9=='a')||(ch9=='b')||(ch9=='d'))
		      cout<<"\n\n\t\t Oops ! You are wrong !\n\n\t\t The correct answer is c) Electro Magnetic device.\n\n";
		      else
		      { cout<<"\n\n\t\t Invalid option !!!\n\n\t\t Please enter a valid option (a,b,c,d).\n\n\t\t ";
			goto EE;
		      }
		    }
		    { clrscr();
		      cout<<"\n\n\t\t Q9: Who is the founder of Bing ?\n\n";
		      cout<<"\t\t a) Steve Ballmer\n\n\t\t b) David Filo\n\n\t\t c) Jeny Yang\n\n\t\t d) None of the above\n\n\t\t ";
		   FF:cin>>ch10;
		      if(ch10=='a')
		      { x = x + 10;
			cout<<"\n\n\t\t Absolutely correct !\n\n\t\t Your score is : "<<x<<"\n\n";
		      }
		      else
		      { if((ch10=='b')||(ch10=='c')||(ch10=='d'))
			cout<<"\n\n\t\t Wrong answer !\n\n\t\t The correct answer is a) Steve Ballmer.\n\n";
			else
			{ cout<<"\n\n\t\t Invalid option !!!\n\n\t\t Please enter a valid option (a,b,c,d).\n\n\t\t ";
			  goto FF;
			}
		      }
		      { clrscr();
			cout<<"\n\n\t\t Q10: Who are the founders of Google ?\n\n";
			cout<<"\t\t a) Larry Page & Sergey Brin\n\n\t\t b) Jawed Karim & Chad Hurley\n\n\t\t c) Steve Chen & Chad Hurley\n\n\t\t d) Jerry Yang & Steve Ballmer\n\n\t\t ";
		     GG:cin>>ch11;
			if(ch11=='a')
			{ x = x + 10;
			  cout<<"\n\n\t\t Brilliant Job !\n\n\t\t Your score is : "<<x<<"\n\n";
			}
			else
			{ if((ch11=='b')||(ch11=='c')||(ch11=='d'))
			  cout<<"\n\n\t\t Sorry wrong answer !\n\n\t\t The correct answer is a) Larry Page & Sergey Brin.\n\n";
			  else
			  { cout<<"\n\n\t\t Invalid opiton !!!\n\n\t\t Please enter a valid option (a,b,c,d).\n\n\t\t ";
			    goto GG;
			  }
			}
			{ clrscr();
			  cout<<"\n\n\n\t\t Well Done ! ";
			  cout<<"\n\n\t\t Here's the result ";
			  cout<<"\n\n\n\t\t\t\t LOADING";
			  delay(1000);
			  cout<<".";
			  delay(1000);
			  cout<<".";
			  delay(1000);
			  cout<<".";
			  delay(1000);
			  cout<<".";
			  delay(2000);
			  if((x==100)||(x==90)||(x==80))
			  { cout<<"\n\n\t\t AWESOME !!!\n\t\t You are Extremely BRILLIANT !!!\n\t\t Keep it up !\n\t\t Your total score is : "<<x;
			  }
			  else
			  { if((x==70)||(x==60)||(x==50))
			    cout<<"\n\n\t\t Good Job !\n\t\t You can perform more better.\n\t\t Your score is : "<<x;
			    else
			    { if((x==40)||(x==30))
			      cout<<"\n\n\t\t You are Average !\n\t\t Better luck next time !\n\t\t Your total score is : "<<x;
			      else
			      cout<<"\n\n\t\t Not a Good performance !!!\n\t\t Your total score is : "<<x;
			    }
			  }
			}
		      }
		    }
		  }
		}
	      }
	    }
	  }
	}
      }
    }
  }
}



What I have tried:

The portion given below of all the questions is not showing any output !

if(ch5=='d')
	    { x = x + 10;
	      cout<<"\n\n\t\t Great Job !\n\n\t\t Your score is : "<<x<<"\n\n";
	    }
	    else
	    { if((ch5=='a')||(ch5=='b')||(ch5=='c'))
	      cout<<"\n\n\t\t Sorry wrong answer !\n\n\t\t The correct answer is d) Photoelectric cells.\n\n";
	      else
	      { cout<<"\n\n\t\t Invalid option !!!\n\n\t\t Please enter a valid opition (a,b,c,d).\n\n\t\t ";
		goto AA;
	      }
	    }

解决方案

1) It's not urgent. It's urgent to you, because you have procrastinated and left it too late to hand in.
2) It's badly indented, so it's very hard to read and work out what is going on.
3) It's full of goto statements which make it even harder to work out what is going on.
4) We can't fix it for you because we have no idea what it is supposed to do, or what inputs you are providing to make it cause the problem. Remember, we have no access to your homework question, much less your HDD or screen...
5) Getting your code working is part of your task!

So, its going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. How you use it depends on your compiler system, but a quick Google for the name of your IDE and "debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!


Griff is right the goto are making the code unreadable. Make some output for your problematic ch5 to see what is going on.

Try to eliminate ALL goto statements and use subfuctions for cleaner code.

I would write only:

cin >> ch5;


这篇关于请帮忙 !这很紧急 。下面给出的代码没有显示if条件的输出。请帮我解决问题!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆