2016-04-19 4 views
0

は表示されません。このコードは、エラーを生成しませんが、出力にちょうどこのラインは、プログラムが終了するまで表示されます:C++クラスは、出力が完全に

cout << "write 1 for areaoftrapezium and 2 for areaofrhombus and 3 for      areaofParallelogram " << endl; 
cin >> option; 

と、ここで私は知らない完全なコード何が間違っていますか

#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 for areaoftrapezium and 2 for areaofrhombus and 3 for areaofParallelogram " << endl; 
cin >> option; 
switch (option) { 

case '1': 
{ 
    cout << "Enter the value for two bases & height of the trapezium: " <<  endl; 
    cin >> a; 
    cin >> b; 
    cin >> c; 

    project obj(a, b, c); 
    obj.trapezium(); 

} 
break; 

case '2': 
{ 
    cout << "Enter diagonals of the given rhombus:" << endl; 
    cin >> d; 
    cin >> e; 
    project obj(d, e); 
    obj.rhombus(); 
} 
break; 

case '3': 
{ 
    cout << "Enter base and altitude of the given Parallelogram: " << endl; 
    cin >> f; 
    cin >> h; 
    project obj(f, h); 

    obj.Parallelogram(); 

} 
break; 

} 

system("pause"); 
return 0; 

} 

私に紛失しているものを教えてください。

+0

スイッチケースにデフォルトブロックを追加して、そのブロックに入るかどうかを確認してください。 – Bettorun

答えて

5

のように数字のような数字が混乱しています。彼らはまったく違うものです。ナンバーワンは、私が持っている頭の数です。数字「1」は、アラビア数字システムで数字1を表すことができるマークである。

int option = 0; 

いいえ、optionは整数です。

cin >> option; 

あなたはユーザーから整数を読み取ります。

switch (option) { 
case '1': 

そしてあなたはナンバーワンにそれを比較したい除いて、文字1と比較します。

ユーザーから数字を読み取った場合は、数字を1と同じように比較してください。ユーザーから文字を読み取った場合は、'1'などの文字と比較してください。それをまっすぐに保つ。

関連する問題