0 c++
此代码不会产生任何错误,但在输出中只显示此行,然后程序退出:
cout << "write 1 for areaoftrapezium and 2 for areaofrhombus and 3 for areaofParallelogram " << endl;
cin >> option;
Run Code Online (Sandbox Code Playgroud)
这里的完整代码我不知道出了什么问题
#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;
}
Run Code Online (Sandbox Code Playgroud)
请告诉我我错过了什么?
你是数字的混淆,比如一个数字,比如'1'.它们是完全不同的东西.第一个是我有多少头.数字"1"是可以表示阿拉伯数字系统中的第一个的标记.
int option = 0;
Run Code Online (Sandbox Code Playgroud)
好的,option是一个整数.
cin >> option;
Run Code Online (Sandbox Code Playgroud)
并且您从用户读取整数.
switch (option) {
case '1':
Run Code Online (Sandbox Code Playgroud)
然后你将它与角色1进行比较,除非你想将它与第一个进行比较.
如果您从用户那里读取数字,请将它们与一个数字进行比较.如果您从用户那里读取字符,请将它们与字符进行比较'1'.保持笔直.
| 归档时间: |
|
| 查看次数: |
31 次 |
| 最近记录: |