c++ class the output doesn't display completely -
this code produces no errors, in output line show program exits:
cout << "write 1 areaoftrapezium , 2 areaofrhombus , 3 areaofparallelogram " << endl; cin >> option;
and here full code don't know wrong
#include<iostream> using namespace std; class project { private: float base, base2, height; float diagonal, diagonal2; float base3, aldtude; public: void trapezium() { float areaoftrapezium; areaoftrapezium = 0.5*(base + base2)*height; cout << "the area of trapezium is:" << areaoftrapezium; } void rhombus() { float areaofrhombus; areaofrhombus = 0.5*diagonal*diagonal2; cout << "the area of rhombus is:" << areaofrhombus; } void parallelogram() { float areaofparallelogram; areaofparallelogram = base3*aldtude; cout << "the area of parallelogram is:" << areaofparallelogram; } project(int a, int b, int c){ base = a; base2 = b; height = c; } project(int d, int e) { diagonal = d; diagonal2 = e; } float getbase() { return base; } float getbase2() { return base2; } float getheight() { return height; } float getdiagonal() { return diagonal; } float getdiagonal2() { return diagonal2; } float getbase3() { return base3; } float getaldtude() { return aldtude; } }; int main() { int a, b, c, d, e, f, h; int option = 0; project obj(); cout << "write 1 areaoftrapezium , 2 areaofrhombus , 3 areaofparallelogram " << endl; cin >> option; switch (option) { case '1': { cout << "enter value 2 bases & height of trapezium: " << endl; cin >> a; cin >> b; cin >> c; project obj(a, b, c); obj.trapezium(); } break; case '2': { cout << "enter diagonals of given rhombus:" << endl; cin >> d; cin >> e; project obj( d, e); obj.rhombus(); } break; case '3': { cout << "enter base , altitude of given parallelogram: " << endl; cin >> f; cin >> h; project obj( f, h); obj.parallelogram(); } break; } system("pause"); return 0; }
please tell me i'm missing?
you confusing numbers, one, digits, '1'
. different things. number 1 how many heads have. digit "1" mark can represent number 1 in arabic numeral system.
int option = 0;
okay, option
integer.
cin >> option;
and read integer user.
switch (option) { case '1':
and compare character 1
, except wanted compare number one.
if read numbers user, compare them numbers one. if read characters user, compare them characters '1'
. keep straight.
Comments
Post a Comment