错误!二进制'operator<<' 'float'和'const char [2]'类型的无效操作数



我正在尝试制作一个程序,它相当于两个分数的四函数计算器。。错误出现在cout语句中的每个switch案例中。错误为:

[Error]类型为"float"one_answers"const char[2]"的无效操作数二进制运算符<lt;'

我试着在谷歌上搜索,没有发现任何结果,但我确实发现了同样的错误,但使用了int而不是float。不幸的是,他犯了一个明显的错误,他甚至没有使用cout语句并将<lt;操作员。此外,我尝试添加更多的括号来指定首先执行哪些数学运算,但没有效果。

#include <iostream>
#include <conio.h>
using namespace std;
main()
{   //This Program is an equivalent of a four function calculator for fraction
float N1, D1, N2, D2;
char OP, slash;
system("cls");

cout<<"Hint: Enter Both Fractions with Operator in between; 1/2 + 6/3";
cout<<"nEnter Fractionaly Binary Operation: ";
cin>>N1>>slash>>D1>>OP>>N2>>slash>>D2;
if(slash=='/')
{
switch(OP) 
{
case '+':
cout<<"Addition of Given Fraction is: ("<<N1<<"/"<<D1<<") + ("<<N2<<"/"<<D2<<") = "<<(((N1*D2)+(N2*D1))<<"/"<<(D1*D2))<<" = "<<(((N1*D2)+(N2*D1))/(D1*D2))<<endl;
break;
case '-':
cout<<"Subtraction of Given Fraction is: ("<<N1<<"/"<<D1<<") - ("<<N2<<"/"<<D2<<") = "<<(((N1*D2)-(N2*D1))<<"/"<<(D1*D2))<<" = "<<(((N1*D2)-(N2*D1))/(D1*D2))<<endl;
break;
case '*':
cout<<"Multiplication of Given Fraction is: ("<<N1<<"/"<<D1<<") * ("<<N2<<"/"<<D2<<") = "<<((N1*N2)<<"/"<<(D1*D2))<<" = "<<((N1*N2)/(D1*D2))<<endl;
break;
case '/':
cout<<"Division of Given Fraction is: ("<<N1<<"/"<<D1<<") / ("<<N2<<"/"<<D2<<") = "<<((N1*D2)<<"/"<<(D1*N2))<<" = "<<((N1*D2)/(D1*N2))<<endl;
break;
default:
cout<<"INVALID OPERATOR!";
getch();
system("cls");
return(0);
}
}
else
{
cout<<"INVALID INPUT!";
getch();
system("cls");
return(0);
}


getch();
system("cls");
return(0);
}

以下几行中也出现了相同的错误。。

case '+':
cout<<"Addition of Given Fraction is: ("<<N1<<"/"<<D1<<") + ("<<N2<<"/"<<D2<<") = "<<(((N1*D2)+(N2*D1))<<"/"<<(D1*D2))<<" = "<<(((N1*D2)+(N2*D1))/(D1*D2))<<endl;
break;

case '-':
cout<<"Subtraction of Given Fraction is: ("<<N1<<"/"<<D1<<") - ("<<N2<<"/"<<D2<<") = "<<(((N1*D2)-(N2*D1))<<"/"<<(D1*D2))<<" = "<<(((N1*D2)-(N2*D1))/(D1*D2))<<endl;
break;

case '*':
cout<<"Multiplication of Given Fraction is: ("<<N1<<"/"<<D1<<") * ("<<N2<<"/"<<D2<<") = "<<((N1*N2)<<"/"<<(D1*D2))<<" = "<<((N1*N2)/(D1*D2))<<endl;
break;

case '/':
cout<<"Division of Given Fraction is: ("<<N1<<"/"<<D1<<") / ("<<N2<<"/"<<D2<<") = "<<((N1*D2)<<"/"<<(D1*N2))<<" = "<<((N1*D2)/(D1*N2))<<endl;

我必须将此作为作业提交。

这是我想要的界面。注意:这是使用cout语句完成的,后端没有计算。

检查括号:

cout<<"Addition of Given Fraction is: ("<<N1<<"/"<<D1<<") + ("<<N2<<"/"<<D2<<") = "
<<(((N1*D2)+(N2*D1))<<"/"<<(D1*D2))<<" = "<<(((N1*D2)+(N2*D1))/(D1*D2))<<endl;
^                               ^                     

试试这个:

case '+':
cout<<"Addition of Given Fraction is: ("<<N1<<"/"<<D1<<") + ("<<N2<<"/"<<D2<<") = "<<((N1*D2)+(N2*D1))<<"/"<<(D1*D2)<<" = "<<(((N1*D2)+(N2*D1))/(D1*D2))<<endl;
break;
case '-':
cout<<"Subtraction of Given Fraction is: ("<<N1<<"/"<<D1<<") - ("<<N2<<"/"<<D2<<") = "<<((N1*D2)-(N2*D1))<<"/"<<(D1*D2)<<" = "<<(((N1*D2)-(N2*D1))/(D1*D2))<<endl;
break;
case '*':
cout<<"Multiplication of Given Fraction is: ("<<N1<<"/"<<D1<<") * ("<<N2<<"/"<<D2<<") = "<<(N1*N2)<<"/"<<(D1*D2)<<" = "<<((N1*N2)/(D1*D2))<<endl;
break;
case '/':
cout<<"Division of Given Fraction is: ("<<N1<<"/"<<D1<<") / ("<<N2<<"/"<<D2<<") = "<<(N1*D2)<<"/"<<(D1*N2)<<" = "<<((N1*D2)/(D1*N2))<<endl;
break;

中括号不匹配

cout<<"Addition of Given Fraction is: ("<<N1<<"/"<<D1<<") + ("<<N2<<"/"<<D2<<") = "<<
(((N1*D2)+(N2*D1))<<"/"<<(D1*D2))   /*<-here*/
<<" = "<<(((N1*D2)+(N2*D1))/(D1*D2))<<endl;

CCD_ 1在一个块中。

相关内容

最新更新