0
Write a c++ program. Make sure your program handle all validations Use at Least One class. C= 1/b + 2 / (a+1)
#include<cstdlib> #include<iostream> #include<math.h> using namespace std; class Coding{ private: double a, b, c; public: void display(); Coding(){ cout<<"Enter the value for a: "; cin>>a; cout<<"Enter the value for b: "; cin>>b; if(a!=-1) { cout<<"a cannot be -1" ; } if (b!=0) { c=(1 / b) + 2 / (a + 1); cout<<"c = "; cout << c << endl; } else{ cout << "b cannot be zero: "; } } }; int main(){ Coding myCoding; myCoding.display( value a, value b); } Please I Need A Helping Hand đ I'm Getting Errors At The Last Line
1 Answer
+ 1
you have not defined the display function. Also what is value a, value b?
in your constructor there is assignment to private variables a and b, they are not visible outside your class. you can call display() without arguments and print a and b inside display function.
also i believe there is logic error for (a != -1) because if value cannot be -1 it should be a == -1. but if you are checking for negative values a < 0 is better.