C++小白求助一个问题
本帖最后由 1627550352 于 2014-10-24 21:11 编辑#include "stdlib.h "
#include "stdafx.h"
#include<iostream>
using namespace std;
int calc(int a);
int calc(int a, int b);
int calc(int a,int b,int c);
int calc(int a)
{
int f;
f = a*a;
return f;
}
int calc(int a, int b)
{
int f;
f = a*b;
return f;
}
int calc(int a, int b, int c)
{
int f;
f = a + b + c;
return f;
}
int main()
{
int a, b, c,d,temp;
cout << "选择功能:1为求参数平方值;2为求两个参数的积;3为求三个参数的和"<<"\n\n";
cout << "请输入选择的功能数字"<<"\n\n";
//cin.ignore(100, '\n');
//cout << "\n";
cin >> temp;
cin.ignore(100, '\n');
cout << "\n";
switch (temp)
{
case '1':
cout << "请输入一个参数a的值"<<"\n\n";
cin >> a;
d = calc(a);
break;
case '2':
cout << "请输入参数a、b的值"<<"\n\n";
cin >> a;
cin >> b;
d = calc(a, b);
break;
case '3':
cout << "请输入参数a、b、c的值"<<"\n\n";
cin >> a;
cin >> b;
cin >> c;
d = calc(a, b, c);
break;
default:
temp = 'E';
break;
}
if (temp != 'E')
{
if (temp == '1')
{
cout << "a" << "*" << "a" << "=" << d << "\n\n";
}
else if (temp == '2')
{
cout << "a" << "*" << "b" << "=" << d << "\n\n";
}
else if (temp == '3')
{
cout << "a" << "+" << "b" <<"c"<< "=" << d << "\n\n";
}
}
else
{
cout << "输入错误!" << "\n\n";
}
std::cout << "请输入任何字符结束!" << "\n\n";
system("pause");
return 0;
}
为什么实现不了功能呢
大神呢, case '1'是字符串吧 小嗯嗯 发表于 2014-10-25 01:04
case '1'是字符串吧
果然是啊,temp定义为char型就可以了。。。谢谢啦。。。困扰了一天也没看出哪里有问题。。。终于解决了。有信心学下去了。哈哈
页:
[1]