#include <iostream> #include <iomanip> using namespace std; double const PI = 3.
ID: 3732829 • Letter: #
Question
#include <iostream>
#include <iomanip>
using namespace std;
double const PI = 3.141592;
void getDataa(double base, double height);
void getData(double radiusa, double radiusb);
void printData(double rec_area, double elli_area);
int main()
{
double base, height, radiusa, radiusb, rec_area, elli_area;
cout << "For the rectangle" << endl;
getDataa(base, height);
cout << "For the ellipse" << endl;
getData(radiusa, radiusb);
rec_area = base * height;
elli_area = PI * radiusa * radiusa;
printData(rec_area, elli_area);
return 0;
}
void getDataa(double base, double height) {
cout << "Please enter two lengths " << endl;
cin >> base;
cin >> height;
}
void getData(double radiusa, double radiusb) {
cout << "Please enter two lenghts " << endl;
cin >> radiusa;
cin >> radiusb;
}
void printData(double rec_area, double elli_area) {
cout << "The area of the rectangle is ";
cout << fixed << setprecision(1) << rec_area << endl;
cout << "The area of the ellipse is ";
cout << fixed << setprecision(1) << elli_area << endl;
}
Why does Visual Studio 2017 give me a " run-time check error #3- variable is being ussed without being initialized" how do i fix this? When i use an online c++ compiler I get no errors.
C++ code being used :
Explanation / Answer
Initialize all the variables to 0(did in the below code). You implementation to get data is not right because after getting the user input using the function how can variables in the main can get the user's input. Take user input (cin) in the main itself.
#include <iostream>
#include <iomanip>
using namespace std;
double const PI = 3.141592;
void getDataa(double base, double height);
void getData(double radiusa, double radiusb);
void printData(double rec_area, double elli_area);
int main()
{
double base = 0, height = 0, radiusa = 0, radiusb = 0, rec_area = 0, elli_area = 0;
cout << "For the rectangle" << endl;
getDataa(base, height);
cout << "For the ellipse" << endl;
getData(radiusa, radiusb);
rec_area = base * height;
elli_area = PI * radiusa * radiusa;
printData(rec_area, elli_area);
return 0;
}
void getDataa(double base, double height) {
cout << "Please enter two lengths " << endl;
cin >> base;
cin >> height;
}
void getData(double radiusa, double radiusb) {
cout << "Please enter two lenghts " << endl;
cin >> radiusa;
cin >> radiusb;
}
void printData(double rec_area, double elli_area) {
cout << "The area of the rectangle is ";
cout << fixed << setprecision(1) << rec_area << endl;
cout << "The area of the ellipse is ";
cout << fixed << setprecision(1) << elli_area << endl;
}
**Comment for any further queries.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.