c++问题 关于结构error: expected primary-expression before ✀{✀ token

2024年11月23日 01:36
有4个网友回答
网友(1):

如下:

#include

#include

using namespace std;

int main(int argc, char *argv[])

{

int number(0);

double number1(0);

double number2(0);

struct Convert

{

char convert_name[100];

double convert_rate;

};

Convert convert[3] = {{{"yuan to dollar"},0.125},{"dollar to pound",2},{"yuan to

pound",0.0625}};

cout<<"choose a way to convert money"<

pound"<

cin>>number;

cout<<"please enter the type that you want to convert";

cin>>number1;

if(number<3&&number>=0)

number2=number1*convert[number-1].convert_rate;

else

cout<<"sorry ,you entered a wrong number";

cout<

system("PAUSE");

return EXIT_SUCCESS;

}

扩展资料:

C++常用函数:

int abs(int x):求整数x的绝对值 

double acos(double x):计算arcos(x)的值 

double asin(double x):计算arsin(x)的值 

double atan(double x):计算arctan(x)的值 

double cos(double x):计算cos(x)的值 

double cosh(double x):计算x的双曲余弦cosh(x)的值 

double exp(double x):求的值 

double fabs(double x):求实数x的绝对值 

double fmod(double x):求x/y的余数 

long labs(long x):求长整型数的绝对值 

double log(double x):计算In(x)的值

double log10(double x):计算的值 

double modf(double x, double *y):取x的整数部分送到y所指向的单元格中 

double pow(double x, double y):求x的y次幂的值 

double sin(double x):计算sin(x)的值 

double tan(double x):计算tan(x)的值 

void abort(void):终止程序执行   

void exit(int):终止程序执行   

double atof(const char *s):将s所指向的字符串转换成实数 

int atoi(const char *s):将s所指向的字符串转换成整数 

long atol(const char *s):将s所指的字符串转换成长整数 

int rand(void):产生一个随机整数 

网友(2):

改好了,自己看吧。主要是字符数组初始化的问题,记住只有在定义字符数组的时候才可以用字符串给字符数组赋值。还有一个拼写错误,我也改过来了
#include
#include

using namespace std;

int main(int argc, char *argv[])
{
int number(0);
double number1(0);
double number2(0);
struct Convert
{
char convert_name[100];
double convert_rate;
};
Convert convert[3] = {{{"yuan to dollar"},0.125},{"dollar to pound",2},{"yuan to pound",0.0625}};
cout<<"choose a way to convert money"< cin>>number;
cout<<"please enter the type that you want to convert";
cin>>number1;
if(number<3&&number>=0)
number2=number1*convert[number-1].convert_rate;
else
cout<<"sorry ,you entered a wrong number";
cout<
system("PAUSE");
return EXIT_SUCCESS;
}

网友(3):

是因为在函数调用时 括号里的参数前面还加了变量类型 去掉这个变量类型就行了
(至少我的错误是这样的。。。其他情况就不清楚了)

网友(4):

#include
void main()
{
int a=5,b=3;
scanf("d%,d%",&a,&b);
x=a*b;
printf("d%,d%,d%",a,b,x)
}