Click here to Skip to main content
15,886,773 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C++
#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 !
C++
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;
	      }
	    }
Posted
Updated 7-Jan-18 20:27pm
v2
Comments
Kenneth Haugland 8-Jan-18 1:37am    
Give us more code plz? I'm being sarcastic, just post the code that is relevant to the problem, we are not a debugging service. And drop the please help it's urgent.
Kenneth Haugland 8-Jan-18 1:40am    
Now that it is formatted correctly I see that you are using goto statements. Please stop using those. The code is harder to read/maintain and debugging, as you have found out, is a nightmare.

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!
 
Share this answer
 
Comments
Kenneth Haugland 8-Jan-18 4:24am    
Amen! And I mean that literally here :D
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:
C++
cin >> ch5;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900