; issue with comments

So my code was working absolutely fine until i added the comments which was required by the teacher for the assignment. Once i added the comments, i get an error for line 15 that i need to add a semicolon which makes no sense because it is just empty space between the end of the method and a comment

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
#include <iostream>

using namespace std;

//the method swap1 uses a temporary variable to swap the variables by value/copy
//the parameters are the user inputted variables
//no return value
void swap1(double n1, double n2)
{
    double temp;
    temp = n1;
    n1 = n2;
    n2 = temp;
}

//the method swap2 uses a temporary variable to swap the variables by reference/alias
//the parameters are the user inputted variables
//no return value
void swap2(double & n1, double & n2)
{
    double temp;
    temp = n1;
    n1 = n2;
    n2 = temp;
}

//the main method asks the user to input 2 numbers, calls the swap functions, and prints the 2 swapped variables
//the parameters are the user inputted variables
//the return value is 0
int main()
{
    double n1, n2, temp;
    cout << "Enter first number:" << endl;
    cin >> n1;
    cout << "Enter second number:" << endl;
    cin >> n2;
    cout << endl;
    cout << "The first number: " << n1 << endl;
    cout << "The second number: " << n2 << endl;
    cout << "Calling method swap 1" << endl;
    swap1(n1, n2);
    cout << "The new first number: " << n1 << endl;
    cout << "The new second number: " << n2 << endl;
    cout << "Calling method swap 2" << endl;
    swap2(n1, n2);
    cout << "The new first number: " << n1 << endl;
    cout << "The new second number: " << n2 << endl;
    cout << "Bye" << endl;
    return 0;
}
Last edited on
Your code compiles fine on the latest GCC.
What compiler are you using?
comments should be in one line in your compiler
else use /*comment*/
Last edited on
@Ihatov i'm using codeblocks v12.1 i think

and @suyashsing234 all my comments are one line hahaha but i also used your method and got the same error
your code works in my compiler which is codeblocks v16.01 and there is no need for 'temp' in main
Last edited on
ensure that codeblocks is following c++11 and not c++98.I used to have very weird probelms while using 98
Registered users can post here. Sign in or register to post.