-1

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.

#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;
}
Wu Wew
  • 1
  • 3
    "_`int myTime = Time(int time);`//error in this line_" What should `Time(int time)` mean here? Did you want to invoke the function? If so, it would be `Time (time)`, but then there is no `time` variable defined. Did you mean to invoke it with hardcoded value? e.g. `Time (6)`? Alternatively, consider learning C++ from a [good C++ book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). – Algirdas Preidžius Nov 24 '20 at 14:03

1 Answers1

2
int myTime = Time(int time);//error in this line

Why do you pass int time to the function? It needs to be a number from 1 - 24

int myTime = Time(10);
nils
  • 338
  • 2
  • 11