C++ 101: With C/C++/C# languages, structures are delimited with
{
and
}
, they go in pairs, for each opening one, there is a closing one.
As you can see after indentation, your code have a couple
}
missing.
Learn to indent properly your code, it show its structure and it helps reading and understanding.
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
#define false 0
#define true 1
#define bool int
void responsegood();
void responsebad();
void generatePattern1(int*, int*);
void generatePattern2(int*, int*);
void generatePattern3(int*, int*);
int main()
{
int a,b,no,mul;
char ch;
int i ;
int level;
bool correct=true;
int passes;
srand(time(NULL));
printf("Choose your level of difficulty (1-3)\n");
scanf("%d", &level);
while (level !=-1){
do{
if((level != 1 && level != 2) && (level != 3 && level !=-1)){
printf("The value is invalid\n");
printf("Choose your level of difficulty (1-3)\n");
scanf("%d", &level);
}
}
while ((level !=1 && level !=2) && (level !=3 && level !=-1));
while (level !=-1){
do{
if(level == 1){
generatePattern1(&a, &b);
}
else if(level == 2){
generatePattern2(&a, &b);
}
else if(level == 3){
generatePattern3(&a ,&b);
while(correct)
{
passes=0;
for (i = 1 ; i <= 10 ; ++i ) {
a=rand()%10;
b=rand()%10;
printf("How much is %d times %d = ",a,b);
scanf("%d",&no);
mul=a*b;
if(mul==no)
{
responsegood();
passes++ ;
}
else
{
responsebad();
}
}
if ( passes < 7.5 ) {
printf( "Please ask your teacher for extra help.\n" );
}
else {
printf( "Congratulations , you are ready to go to the next level!\n " );
}
do{
printf("\nWant to try another multiplication question? If yes then press 'y' else 'n' = ");
scanf(" %c",&ch);
if(ch=='y'||'Y')
{
continue;
}
else if (ch=='n'||'N')
{
correct=false;
}
else
{
printf("invalid value\n");
}
}while ((ch !='y'&&ch !='n')&&(ch !='Y'&&ch !='N'));
}
system("pause");
return 0;
}
void responsegood()
{
char rangood;
srand(time(NULL));
rangood = 1 + rand() % 4;
switch (rangood){
case 1:
printf("Very good!\n\n");
break;
case 2:
printf("Excellent!\n\n");
break;
case 3:
printf("Nice work!\n\n");
break;
case 4:
printf("Keep up the good work!\n\n");
break;
}
}
void responsebad()
{
char ranbad;
srand(time(NULL));
ranbad = 1 + rand() % 4;
switch (ranbad){
case 1:
printf("no.please try again!\n\n");
break;
case 2:
printf("wrong,Try again!\n\n");
break;
case 3:
printf("Dont give up!\n\n");
break;
case 4:
printf("No.keep trying!\n\n");
break;
}
}
void generatePattern1(int*a, int*b){
*a = rand() % 9+1;
*b = rand() % 9+1;
}
void generatePattern2(int*a, int*b){
*a = rand() % 99+1;
*b = rand() % 99+1;
}
void generatePattern3(int*a, int*b){
*a = rand() % 999+1;
*b = rand() % 999+1;
return;
}
Professional programmer's editors have this feature and others ones such as parenthesis matching and syntax highlighting.
Notepad++ Home[
^]
ultraedit[
^]
Once you done those corrections, you will need to learn debugger because you have other problems in your code.
There is a tool that allow you to see what your code is doing, its name is
debugger. It is also a great learning tool because it show you reality and you can see which expectation match reality.
When you don't understand what your code is doing or why it does what it does, the answer is
debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.
Debugger - Wikipedia, the free encyclopedia[
^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[
^]
Basic Debugging with Visual Studio 2010 - YouTube[
^]
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.