Recieving error ( Exit was not declared in scope) need help getting code to run
ID: 3906118 • Letter: R
Question
Recieving error ( Exit was not declared in scope) need help getting code to run and also need //comments for each line explaining what they do
#include "circle.h" //define the circle.h header file in the same location where the program is saved
#include "square.h" //define the square.h header file in the same location where the program is saved
#include <iostream>
using namespace std;
int main()
{
char type;
while(true)
{
cout << "Enter type of figure(C - Circle, S - Square or Q - quit: "; cin >> type;
if(type == 'C')
{
Circle* c = new Circle;
c->input();
c->print();
delete c;
}
else if(type == 'S')
{
Square* s = new Square;
s->input();
s->print();
delete s;
}
else if(type == 'Q')
exit(0);
else
cout << "Invalid ";
cout << endl;
}
}
Explanation / Answer
Please update your code as follows:
Updated Code:
#include <iostream>
#include <stdlib.h> //Header file for exit
#include "circle.h" //define the circle.h header file in the same location where the program is saved
#include "square.h" //define the square.h header file in the same location where the program is saved
using namespace std;
int main()
{
char type;
//Loop till user want to quit
while(true)
{
//Prompt user for option
cout << "Enter type of figure(C - Circle, S - Square or Q - quit: "; cin >> type;
//If user enter C
if(type == 'C')
{
//Creating a pointer Circle object
Circle* c = new Circle;
c->input(); //Calling input method present in Circle class
c->print(); //Calling print method present in Circle class
delete c; //Deleting dynamically created object
}
//If user enter S
else if(type == 'S')
{
//Creating a pointer Square object
Square* s = new Square;
s->input(); //Calling input method present in Square class
s->print(); //Calling print method present in Square class
delete s; //Deleting dynamically created object
}
//If user enter Q
else if(type == 'Q')
exit(0); //Exit from program
else
cout << "Invalid ";
cout << endl;
}
}
________________________________________________________________________________________
Please let me know if you need any further assistance...
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.