invalid conversion from ‘int’ to ‘int*’ ?

Hello I'm currently attempting to write a program that takes in user's class information (CRN#), Course Designator (ex.CS162), Section (integer). I need to prompt the user. I need to pass by reference (according to teacher). I need to call the function. My questions are as follows. This is my first time using functions and passing by reference. I do understand that it's an alias. I have watched several youtube videos, but none seem to answer some concerns I have. I made some further corrections and I tried to fix it, but now it says that "course cannot be called as a function?"

1) When I use an array, do I have to pass by reference, ex) char &array[]?
2) Is that correct? I've seen one video were the syntax put the & after char (no space) and I've seen it before name, again no space.
3) I need some general help with my code. I have changed it so many times I'm starting to forget what I had done.
4) Please explain in words as best as possible what it is you're doing when you make corrections.
5)

Thank you so very much!

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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
 1 //Sam Vernaza CS162 Lab # 4 
  2 // Practice with functions
  3 #include <iostream>
  4 #include <cctype>
  5 #include <cstring>
  6 
  7 using namespace std;
  8 
  9 // prototypes here:
 10 
 11 const int  NAME = 45;
 12 const int ARRAY= 22;
 13 const int CRNNAME = 4;
 14 
 15 void user_name (char first [], char last []); //username void function
 16 void course (int & crn, int course [], int & section);// coures void function
 17 
 18 
 19 
 20 int main()
 21 {
 22     char first[NAME]; // First name array
 23     char last[ARRAY]; // First name array
 24     int crn;
 25     int course;
 26     int section;
 27 
 28      user_name(first,last); // user name function call
 29      course(crn, course, section);// course function call
 30 
 31      return 0;
 32 } 
 33 
 34 void user_name (char user[]) //username function
 35 {    
 36       
 37     char response;
 38     
 39     cout << "Enter your name:" << endl;
 40     cin.get(user,NAME,'\n');
 41     cin.ignore(100,'\n');
 42 //    response = toupper(first[0]);
 43 
 44     
 45 //    cout << "Enter Last Name;" << endl;
 46 //    cin.get(last,ARRAY,'\n');
 47 //    cin.ignore(100,'\n');
 48 //    response  = toupper(last[0]);
 49 
 50     cout << "You've Entered: " << user << endl;
 51 }
 52 
 53 
 54 void course(int & crn, int course[], int & section); // courses fucntion
 55 
 56 {
 57     cout << "Enter CRN # (3 numbers): " << endl;
 58     cin >> crn;
 59     cin.ignore (100, '\n');
 60 
 61     cout << "Enter Course Designator(ex CS162): " << endl;
 62     cin.get(course, 6, '\n');
 63     cin.ignore(100, '\n');
 64 
 65     cout << "Course Section: " << endl;
 66     cin >> section;
 67     cin.ignore(100, '\n');
 68 
 69     cout << "Your courses are:\n"
 70          << "CRN # "<< crn << '\n'
 71          << "Course: " << course << '\n'
 72          << "Section: " << section << endl;
 73 }
Last edited on
Also, I'm very new, no pointers.
At first look, you have course declared as an int, but passing that int into course(crn, course, section). You have "course" as an array in your function prototype:
void course (int & crn, int course [], int & section);// coures void functio
Looks like you want course to just be an int, not an array of ints, so fix your prototype and definition.


1. For your purposes, just think of arrays as automatically being passed by "reference" already, so no, you shouldn't do char &arr[]. What's really going on is that "arr" is a pointer to the array, so no data is being copied when you pass it into the function, it writes to the same data the pointer points to.
2. Spaces between whatever and the & don't matter.

I'd also suggest not having a function name be the same as a variable name.
Last edited on
Topic archived. No new replies allowed.