这是该程序的第一阶段,当我尝试运行它并把它立即转到其他它不读取如果
#include <iostream>
#include <string>
using namespace std;
void main()
{
double x, y;
double cost;
char frt;
char Frcr;
char crow;
char R , r, F , f ;
int yes = 0, Yes = 0, No = 0, no = 0;
cout << "Please Enter length and Width of the picture in Inches :\n";
cin >> x >> y;
cout << "Please Enter the Type of the Frame (R/F)(R Stands for Regular ,F Stands for Fancy) : \n";
cin >> frt;
if ('frt' == 'r' || 'frt' == 'R')
{
cost = (x + y)*0.15;
cout << "Do you want to color the frame? (Yes/No) : \n";
cin >> Frcr;
if ('frcr' == yes || 'frcr' == Yes)
{
cost = (x + y)*0.15;
cout << "The Cost is : " << (x + y)*0.15 + ((x + y)*0.10) << endl;
}
else if ('frcr' == no || 'frcr' == No)
{
cost = ((x + y)*0.15);
cout << "The Cost Is : " << cost << endl;
}
}
else
cout << "There is an Error " << endl;
}
编辑:在工作人员的帮助下工作守则:)
#include <iostream>
using namespace std;
void main()
{
double x, z;
double cost;
char frt;
char Frcr;
int Crow;
int R, r, F, f;
int y, Y, N, n;
cout << "Please Enter The Width of the picture in Inches :";
cin >> x;
cout << "Please Enter The length of the picture in Inches :";
cin >> z;
cout << "Please Enter the Type of the Frame (R/F):" << endl;
cout << "(R Stands for Regular ,F Stands for Fancy) \n";
cin >> frt;
if (frt == 'r' || frt == 'R')
{
cost = (x + z)*0.15;
cout << "Do you want to color the frame? (Y/N) : \n";
cin >> Frcr;
if (Frcr == 'y' || Frcr == 'Y')
{
cout << "Type The Number Of The Crowns You Want ? :";
cin >> Crow;
cout << "The cost With Frame Coloring : " << ((x + z)*0.15) + ((x + z)*0.10) + (Crow*0.35) << endl;
}
else if (Frcr == 'N' || Frcr == 'n')
{
cout << "Type The Number Of The Crowns You Want ? :";
cin >> Crow;
cout << "The Cost is : " << ((x + z)*0.15) + (Crow*0.35) << endl;
}
else
cout << "Invalid Input." << endl;
}
else if (frt == 'f' || frt == 'F')
{
cout << "Do you want to color the frame? (Y/N) : \n";
cin >> Frcr;
if (Frcr == 'y' || Frcr == 'Y')
{
cout << "Type The Number Of The Crowns You Want ? :";
cin >> Crow;
cout << "The cost With Frame Coloring : " << ((x + z)*0.25) + ((x + z)*0.10) + (Crow*0.35) << endl;
}
else if (Frcr == 'N' || Frcr == 'n')
{
cout << "Type The Number Of The Crowns You Want ? :";
cin >> Crow;
cout << "The Cost is : " << ((x + z)*0.25) + (Crow*0.35) << endl;
}
else
cout << "Invalid Input." << endl;
}
else
cout << "Invalid Input." << endl;
}
答案 0 :(得分:1)
这'frt' == 'r'
错了。 frt
,fcrcr
都是变量。删除&#39; &#39 ;.它应该是:
frt == 'r'
由于许多原因,此'frcr' == yes
也是错误的。 frcr
也是一个变量,所以再次移除&#39; &#39 ;.即使这样,你也不能frcr == "yes"
而是:
1)将frcr
更改为std::string
或
2)保留char
并将"yes"
更改为'y'
或'Y'
。
编辑:你的代码在很多方面都是错误的。我建议你从基础开始。你需要学习。
答案 1 :(得分:0)
最终工作代码。谢谢你们帮助它现在工作正常:) 如果与图片不同,请告诉我
#include <iostream>
using namespace std;
void main()
{
double x, z;
double cost;
char frt;
char Frcr;
int Crow;
int R , r, F , f ;
int y , Y , N , n;
cout << "Please Enter The Width of the picture in Inches :";
cin >> x;
cout << "Please Enter The length of the picture in Inches :";
cin >> z;
cout << "Please Enter the Type of the Frame (R/F)(R Stands for Regular ,F Stands for Fancy) : \n";
cin >> frt;
if (frt == 'r' || frt == 'R')
{
cost = (x + z)*0.15;
cout << "Do you want to color the frame? (Y/N) : \n";
cin >> Frcr;
if (Frcr == 'y' || Frcr == 'Y')
{
cout << "Type The number of the crowns you want ? :";
cin >> Crow;
cout << "The cost With Frame Coloring : " << ((x + z)*0.15) + ((x + z)*0.10)+(Crow*0.35) << endl;
}
else if (Frcr == 'N' || Frcr == 'n')
{
cout << "Type The number of the crowns you want ? :";
cin >> Crow;
cout << "The Cost is : " << ((x + z)*0.15) + (Crow*0.35) << endl;
}
else
cout << "Invalid Input." << endl;
}
else if (frt == 'f' || frt == 'F')
{
cout << "Do you want to color the frame? (Y/N) : \n";
cin >> Frcr;
if (Frcr == 'y' || Frcr == 'Y')
{
cout << "Type The number of the crowns you want ? :";
cin >> Crow;
cout << "The cost With Frame Coloring : " << ((x + z)*0.25) + ((x + z)*0.10)+(Crow*0.35) << endl;
}
else if (Frcr == 'N' || Frcr == 'n')
{
cout << "Type The number of the crowns you want ? :";
cin >> Crow;
cout << "The Cost is : " << ((x + z)*0.25) + (Crow*0.35) << endl;
}
else
cout << "Invalid Input." << endl;
}
else
cout << "Invalid Input." << endl;
}