expected primary-expression before "int"

I am a beginner student learning functions. I had an assignment to complete regarding functions and have an error that appears on line 25 stating "expected primary-expression before "int"". When I try to run my program through g++ the program is not displaying the displayMessages. Any input as to how to fix this error would be greatly appreciated!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
using namespace std;

void displayMessage (string name, int age);
void displayMessage (int num1, int num2);

int main ()
{
  string name;
  int age;
  cout << "Enter your name:" << endl;
  cin >> name;
  cout << "Enter your age:" << endl;
  cin >> age;

  displayMessage (name, age);

  int num1;
  int num2;
  cout << "Enter an integer:" << endl;
  cin >> num1;
  cout << "Enter another integer:" << endl;
  cin >> num2;

  displayMessage (int num1, int num2);

  return 0;
}

void displayMessage (string name, int age)
{
    cout << "Hello," << name << endl;
    cout << "You are" << age << "years old" << endl;
}

void displayMessage (int num1, int num2)
{
  int sum = num1 + num2;
  int difference = num1 - num2;
  cout << "The sum of the integers is" << sum << endl;
  cout << "The difference of the two integers is" << difference << endl;
}



Line 25 should be displayMessage(num1, num2);

The type names should only be present when you declare a variable, not when you make a function call.
Last edited on
My program works perfectly! Thank you so much for your help, I really appreciate it! :)
Topic archived. No new replies allowed.