i正在创建以下代码,该代码正在通过使用负面应对策略的使用来推论学生的压力水平,并与低自我形象相关的陈述一致。以下是我的代码,粗体是我有问题的部分:
void statements (void);
void printweightsstatements(void);
void coping (void);
void printweightscoping(void);
void advice ();
int cumweightstatement();
int cumweightcoping();
void main()
{
statements ();
coping ();
**if (int cumweightstatement + int cumweightcoping>=20)**
printf ("You are very stressed and at a high risk for depression. Please
see a doctor or psychiaqtrist as soon as possiblen");
else if (cumweightstatement + cumweightcoping>=15 && int cumweightstatement + int cumweightcoping<20)
printf ("You are quite stressed and at a moderate risk for depression. Please see your school guidance counselorn");
else if (cumweightstatement + cumweightcoping<=14)
printf ("You are mildly stressed and at a low risk for depression, but you could still benefit from using positive coping strategiesn")
}
void printweightsstatements()
{
printf("1:Strongly disagreen");
printf("2:Disagreen");
printf("3:Neither agree nor disagreen");
printf("4:Agreen");
printf("5:Strongly agreen");
}
void statements(void)
{
int weight1;
int weight2;
int weight3;
int weight4;
printf ("How much do you agree with the following statements?n");
printf ("Statement 1: I have trouble concentrating on my homework for 1 hour straightn");
printweightsstatements;
printf("1:Strongly disagreen");
printf("2:Disagreen");
printf("3:Neither agree nor disagreen");
printf("4:Agreen");
printf("5:Strongly agreen");
printf ("Statement 2: I do not have much control over events in my lifen");
printweightsstatements;
printf("1:Strongly disagreen");
printf("2:Disagreen");
printf("3:Neither agree nor disagreen");
printf("4:Agreen");
printf("5:Strongly agreen");
scanf("%d", &weight2);
printf ("Statement 3: During this school year, I have been stressed a lotn");
printweightsstatements;
printf("1:Strongly disagreen");
printf("2:Disagreen");
printf("3:Neither agree nor disagreen");
printf("4:Agreen");
printf("5:Strongly agreen");
scanf("%d", &weight3);
printf ("Statement 4: Although I try very hard, there is always some schoolwork too difficult for men");
printf("1:Strongly disagreen");
printf("2:Disagreen");
printf("3:Neither agree nor disagreen");
printf("4:Agreen");
printf("5:Strongly agreen");
scanf("%d", &weight4);
printweightsstatements;
int cumweightstatement=weight1+weight2+weight3+weight4;
}
void coping (void);
{
int weight1;
int weight2;
int weight3;
int weight4;
int weight5;
printf ("How often do you use each of the following coping strategies?n");
printf ("Strategy 1: Negative self-talk (for example, I can’t do this,this is too hard for me, I’ll never get good at this)n");
printweightscoping;
scanf("%d", &weight1);
printf ("Strategy 2: Overusing Internet/social media/phone for non-school-related activities (over 1 hour/day)n");
printweightscoping;
scanf("%d", &weight2);
printf ("Strategy 3: Extended sleep or naps (above 8-9 hours of regular sleep)n");
printweightscoping;
scanf("%d", &weight3);
printf ("Strategy 4:Procrastination or avoiding the task (leaving your schoolwork to the last minute, or not doing it at all)n");
printweightscoping;
scanf("%d", &weight4);
printf ("Strategy 5:Denial (ignoring your problems and keep doing things the same way)n");
printweightscoping;
scanf("%d", &weight5);
int cumweightcoping=weight1+weight2+weight3+weight4;
}
void printweightscoping(void);
{
printf("1:Nevern");
printf("2:Rarely(less than weekly) n");
printf("3:Sometimes(once a week)n");
printf("4:Often (several times a week)n");
printf("5:Always (about daily")
}
这是日志。您知道如何解决这些错误?
main.c: In function 'main':
main.c:23:9: error: expected expression before 'int'
main.c:25:33: error: invalid operands to binary + (have 'int (*)()' and 'int (*)
main.c:25:58: error: expected expression before 'int'
^
main.c:27:33: error: invalid operands to binary + (have 'int (*)()' and 'int (*)
expected identifier or '(' before '{' token
a';'在行末尾缺少
printf ("You are mildly stressed and at a low risk for depression, but you could still benefit from using positive coping strategiesn")
,正如评论中所述,您有一些奇怪的声明
else if (cumweightstatement + cumweightcoping>=15 && int cumweightstatement + int cumweightcoping<20)
如果要将变量施加为int,请使用
(int)your_variable
在 int cumweightstatement();
int cumweightcoping();
函数的名称是它在内存中的地址,它解释了为什么您的编译器抱怨添加一些指针(无效操作数(将其用于二进制 (
编辑:您的代码中有很多错误,您声明为函数的变量之间的混淆:int cumweightstatement();
应该是int cumweightstatement;
和某些函数调用未正确完成的调用,例如printweightsstatements;
,应为printweightsstatements();
在函数之外声明变量使其成为Globale:您可以从文件中的任何函数达到它。在函数中声明变量使其位置:您无法从其范围中伸出。即:当您声明时,例如在void statements(void)
中:
int cumweightstatement=weight1+weight2+weight3+weight4;
您声明了一个语言环境变量cumweightstatement
,并影响每个重量的总和。但是,一旦您摆脱功能,您就会尽快失去它。
最简单的是从您拥有的代码开始,就是使用Globale变量,您可能尝试使用声明
int cumweightstatement();
,但再次创建一个函数,而不是globale变量。
此链接https://www.codingunit.com/c-tutorial-functions-and-global-local-variables将为您提供一些依据来声明功能和语言环境/globale变量