[英]C++ expected primary-expression before 'int;
I just want to create my own simple function and I encountered an error that I can't fix.我只想创建自己的简单函数,但遇到了无法修复的错误。 I'm using code blocks.
我正在使用代码块。 The error is "expected primary-expression before 'int' that can be found in a void function. Can you give tips to prevent this error. Thank you and I will appreciate your help.
错误是“在void函数中可以找到'int'之前的预期主要表达式。你能提供一些提示来防止这个错误。谢谢你,我会很感激你的帮助。
#include <iostream>
using namespace std;
int Time(int time)
{
if(time>0 && time<12)
cout<<"Good Morning";
else if(time>=12 && time<17)
cout<<"Good Afternoon";
else if(time>=17 && time<=24)
cout<<"Good Evening";
else
cout<<"Time is between (1-24)";
return time;
}
void print_greet(string name)
{
int myTime = Time(int time);//error in this line
cout<<"Hello "<<name<<myTime<<endl;
}
int myTime = Time(int time);//error in this line
Why do you pass int time
to the function?为什么将
int time
传递给函数? It needs to be a number from 1 - 24它必须是 1 - 24 之间的数字
int myTime = Time(10);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.