c++问题 关于结构error: expected primary-expression before '{' token
#include <cstdlib>
#include <iostream>
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];
convert[0]={"yuan to dollar",0.125};
convert[1]={"dollar to pound",2};
convert[2]={"yuan to pound",0.0625};
cout<<"choose a way to convert money"<<endl<<"1.yuan to dollar"<<endl<<"2.dollar to pound"<<endl<<"3.yuan to 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].couvert_rate;
else
cout<<"sorry ,you entered a wrong number";
cout<<number1<<convert[number-1].convert_name<<" is "<<number2;
system("PAUSE");
return EXIT_SUCCESS;
}
下面是错误信息
Compiler: Default compiler
Building Makefile: "C:\Users\shanliho\Documents\Makefile.win"
Executing make...
make.exe -f "C:\Users\shanliho\Documents\Makefile.win" all
g++.exe -c main.cpp -o main.o -I"lib/gcc/mingw32/3.4.2/include" -I"include/c++/3.4.2/backward" -I"include/c++/3.4.2/mingw32" -I"include/c++/3.4.2" -I"include"
main.cpp: In function `int main(int, char**)':
main.cpp:17: error: expected primary-expression before '{' token
main.cpp:17: error: expected `;' before '{' token
main.cpp:18: error: expected primary-expression before '{' token
main.cpp:18: error: expected `;' before '{' token
main.cpp:19: error: expected primary-expression before '{' token
main.cpp:19: error: expected `;' before '{' token
main.cpp:25: error: 'struct main(int, char**)::Convert' has no member named 'couvert_rate'
make.exe: *** [main.o] Error 1
Execution terminated 展开
如下:
#include <cstdlib>
#include <iostream>
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"<<endl<<"1.yuan to dollar"<<endl<<"2.dollar to
pound"<<endl<<"3.yuan to 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<<number1<<convert[number-1].convert_name<<" is "<<number2;
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):产生一个随机整数
#include <cstdlib>
#include <iostream>
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"<<endl<喊胡<"1.yuan to dollar"<歼闷<endl<<"2.dollar to pound"<<endl<<"3.yuan to 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<<number1<<convert[number-1].convert_name<<" is "<<number2;
system("PAUSE");
return EXIT_SUCCESS;
}
(至少我的错误是这样的。。。其他迅洞情况就不清楚了)
void main()
{
int a=5,b=3;
scanf("孝孝巧d%,d%",&a,&b);
x=a*b;
printf("d%,d%,d%"慎逗,a,b,x)
}