type int unexpected

Hello everyone,

Just edited it as solved after I added:

1
2
3
using namespace std;
using std::vector;
using std::string;


changed to int i2=0, int3=0, int5=0;
and changed "solution" to "Solution".

Many thanks to all the helps!
--------------------------------

[Below was the original post]

this is my first post, and I have read through the instruction
and FAQ, as well as searching for similar questions here and the Web.
Unfortunately, I have not found an answer to the error message yet.
However, please let me know if I missed anything.
Any idea or feedback is highly appreciated!

My code is as below,
and the error message "type int is unexpected" happened for line 15,
which referred to i2, i3 and i5.
I see no issue though.
I am a newbie in C++,
and I saw other people used "struct solution" and all others the same,
and that worked.
However, I hope to know why this generated error, and how I can make it work.

Thank you 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
#include <stdio.h>
#include <vector>
#include <string>

#define NOMINMAX
#define min(a,b)            (((a) < (b)) ? (a) : (b))
#define max(a,b)            (((a) > (b)) ? (a) : (b))

using namespace std;

class solution{
public: 
    int nthUglyNumber(int n){
        vector<int> res(1,1);
        int i2 = 0 , int i3 = 0 , int i5 = 0; //initialize to 0
        while (res.size() < n){
            int m2= res[i2]*2 , m3 = res[i3]*3, m5 = res[i5]*5;
            int mn = min(m2, min(m3, m5));
            if (mn == m2) ++i2; // check which one is the smallest, sort
            if (mn == m3) ++i3;
            if (mn == m5) ++i5;
            res.push_back(mn);
        }
        return res.back();
    }
};






Last edited on
int i2 = 0 , int i3 = 0 , int i5 = 0;
should be
int i2 = 0, i3 = 0, i5 = 0;


What is line 5 supposed to be doing?
Initially I used int i2=0, i3=0, i5=0;
but generated the same error.

line 5 was for max() as I saw there was red curly line for that part so
I searched online to add that to make max() valid.

after changing to int i2 = 0, i3 =0, i5=0;
and added:
using namespace std;
using std::vector;
using std::string;

the Visual Studio Code complied OK,
unfortunately, I pasted it to the online coding test editor,
it generated "use undeclared identifier "Solution", did you mean "solution"?"
However, I used "solution", not "Solution".

Topic archived. No new replies allowed.