Modular programming

Hi, i am requested to created a simple game by my teacher.
this is the correct program and runable:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
void main()
{
char next='y';
float answer, jawapan, mark, count, first_rand, second_rand;
int symbol_rand;

cout << setiosflags(ios::left);
cout << setw(25) <<" "<< "Welcome to Arimetric Game ~ !!"<<endl;
cout << setw(20) <<" "<<"There will be 10 questions per sessions."<<endl;
cout << setw(24) <<" "<<"Each question carries 10 marks."<<endl ;
cout << setw(22) <<" "<<"Lets see how good are you at Maths!"<<endl;
cout << setw(30) <<" "<<"Let the game begin ! "<<endl;
srand((unsigned)time(NULL)) ;

while (next =='y'|| next=='Y')
{
mark = 0;
for (count=1;count<11;count++)
{
first_rand  =  rand()%100+1;
second_rand =  rand()%100+1;
symbol_rand =  rand()%4+1;

cout << "\nQuestion " << count << endl ;

switch (symbol_rand)
{
case 1: cout << first_rand << " + " << second_rand <<" = ";
                answer = first_rand + second_rand;  break;

case 2: cout << first_rand << " - "<< second_rand <<" = ";
                answer = first_rand - second_rand; break;

case 3: cout << first_rand << " * "<< second_rand <<" = ";
                answer = first_rand * second_rand; break;

case 4: cout << "Please input answer in 2 decimal place :"<<endl;
                cout << first_rand << " / "<< second_rand <<" = ";
                answer = first_rand / second_rand; break;
}
cin >> jawapan ;
if( jawapan-answer >=-0.01&&jawapan-answer<=0.01)
{
mark=mark+10;
cout << "\n\t\t\t\t\t\tCorrect! +10 Marks"<<endl ;
}
else
{
mark-=5;
cout << "\n\t\t\t\t\t\tWrong! -5 Marks " << endl ; } }

cout << "\nYou have scored " << mark << " marks. "<<endl <<endl;

cout << "Do you want to keep playing? " ;
cout << "\nType 'y' for yes and 'n' for no: " ;
cin  >> next;
clrscr();
}

cout <<endl<<endl<<setiosflags(ios::right)<<setfill('*')<<setw(45)
        << "Game Over"<<setw(34)<<" "<<endl;
cout << "\n\t\t\t\t\tPress any key to exit . . ."<<endl;
getch();
}


but i woulld like to make it into modular function so that i can get more marks,
so i edited it to :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
void main()
{
char next='y';
float answer, jawapan, mark, count, first_rand, second_rand;
int symbol_rand;
double check (double,double);
cout << setiosflags(ios::left);
cout << setw(25) <<" "<< "Welcome to Arimetric Game ~ !!"<<endl;
cout << setw(20) <<" "<<"There will be 10 questions per sessions."<<endl;
cout << setw(24) <<" "<<"Each question carries 10 marks."<<endl ;
cout << setw(22) <<" "<<"Lets see how good are you at Maths!"<<endl;
cout << setw(30) <<" "<<"Let the game begin ! "<<endl;
srand((unsigned)time(NULL)) ;

while (next =='y'|| next=='Y')
{
mark = 0;
for (count=1;count<11;count++)
{
first_rand  =  rand()%100+1;
second_rand =  rand()%100+1;
symbol_rand =  rand()%4+1;
float check (float,float);
cout << "\nQuestion " << count << endl ;

switch (symbol_rand)
{
case 1: cout << first_rand << " + " << second_rand <<" = ";
                answer = first_rand + second_rand;  break;

case 2: cout << first_rand << " - "<< second_rand <<" = ";
                answer = first_rand - second_rand; break;

case 3: cout << first_rand << " * "<< second_rand <<" = ";
                answer = first_rand * second_rand; break;

case 4: cout << "Please input answer in 2 decimal place :"<<endl;
                cout << first_rand << " / "<< second_rand <<" = ";
                answer = first_rand / second_rand; break;
}
cin >> jawapan ; }

cout << "\nYou have scored " << check(jawapan,answer) << " marks. "<<endl <<endl;

cout << "Do you want to keep playing? " ;
cout << "\nType 'y' for yes and 'n' for no: " ;
cin  >> next;
clrscr();
}

cout <<endl<<endl<<setiosflags(ios::right)<<setfill('*')<<setw(45)
        << "Game Over"<<setw(34)<<" "<<endl;
cout << "\n\t\t\t\t\tPress any key to exit . . ."<<endl;
getch();
}

double check (a, b)
{int mark;
if( a-b >=-0.01&&a-b<=0.01)
{
mark=mark+10;
cout << "\n\t\t\t\t\t\tCorrect! +10 Marks"<<endl ;
}
else
{
mark-=5;
cout << "\n\t\t\t\t\t\tWrong! -5 Marks " << endl ; }
 return  mark;
}

but it shows linker error, when i try to compile it. whats wrong with it/?
Last edited on
Why is your code unindented and what is your link error?
It shows linker error: undesollved external check(double,double)
whats wrong with my function header?
Use int main()

Anyway, you aren't defining the types in your check function on line 60.
http://www.cplusplus.com/doc/tutorial/functions/
Topic archived. No new replies allowed.