Hi, I have a problem that involve global variables. Basicaly, i start in a while loop when a value is true but i cant make that value false when in another function.
I have 2 source files and one header file below.
Could some please tell me where to declare "active" to make this work.
main.c
Code:
#include <stdio.h>
#include <math.h>
#include "functions.h"
bool active = true;
int main()
{
while(active)
{
menu();
}
}
functions.h
Code:
int distance();
void retry();
int quit();
int menu();
lines.c
Code:
#include <stdio.h>
#include <math.h>
struct point2D
{
float x;
float y;
}pa,pb;
int distance()
{
float d;
printf("\nPlease enter the first point: ");
scanf("%f" "%f", &pa.x, &pa.y);
printf("Please enter the second point: ");
scanf("%f" "%f", &pb.x, &pb.y);
d = sqrt(pow(pb.x-pa.x,2)+pow(pb.y-pa.y,2));
printf("The distance between these points is: %f\n\a",d);
return(0);
}
int quit()
{
active = false; //THIS IS THE ERROR!! active: undeclared variable
return(0);
}
int menu()
{
int choice;
printf("\n****************Main Menu*******************\n");
printf("1.Distance between two points\n");
printf("2.Quit\n");
printf("********************************************\n");
printf("Please enter your choice: ");
scanf("%d", &choice);
switch(choice)
{
case 1:
distance();
break;
case 2:
quit();
break;
default:
//retry();
break;
}
return(0);
}