Question
Keep getting the following errors when I try to compile my program in C++ main.cpp: In function int main(): main.cpp:23:1: error: exit was not declared
Keep getting the following errors when I try to compile my program in C++
main.cpp: In function int main(): main.cpp:23:1: error: exit was not declared in this scope exit(0); ^~~~ main.cpp:23:1: note: suggested alternative: _exit exit(0); ^~~~ _exit main.cpp:28:1: error: wait was not declared in this scope wait(NULL); ^~~~ main.cpp:28:1: note: suggested alternative: main wait(NULL); ^~~~ main main.cpp: At global scope: main.cpp:53:1: error: expected unqualified-id before return return 0; ^~~~~~ main.cpp:54:1: error: expected declaration before } token } ^
#include
int num1,num2; puts("Please Type Your First Number: "); scanf("%d",&num1); puts("Please Type Your Second Number : "); scanf("%d",&num2); puts(" Thank You: "); int counter = 0; pid_t pid = fork(); if (pid == 0) { // child process int sum = num1 + num2; int diff = num1 - num2; printf(" The Sum of %d and %d is %d and The Diff is %d",num1,num2,sum,diff); exit(0); } else if (pid > 0) { // parent process wait(NULL); double div; int mul = num1 *num2; if(num2!=0) { div = (double)num1/(double)num2; printf(" The Multiplication of %d and %d is %d and The Division is %lf",num1,num2,mul,div); } else { div=INF; printf(" The Multiplication of %d and %d is %d",num1,num2,mul); printf(" Denominator cannot be zero!Operation division not possible.");
} } else { // fork failed puts("fork() failed! "); return 1; } return 0; }
return 0; }
Errors main.cpp: In function int main(): main.cpp:23:1: error: exit was not declared in this scope exit(0); ^~~~ main.cpp:28:1: error: wait was not declared in this scope wait(NULL); ^~~~ main.cpp: At global scope: main.cpp:53:1: error: expected unqualified-id before return return 0; ^~~~~~ main.cpp:54:1: error: expected declaration before } token } ^
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started