I made some code after watching a YouTube channel. I checked that my code was the same as the video, and the video's code seems to work just fine, but my output doesn't do anything, it is just an empty line.
The code is:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class User {
string status = "Gold";
public:
string first_name;
string last_name;
string get_status() {
return status;
}
};
int add_user_if_not_exists(vector<User> &users, User user) {
for(int i = 0; i = users.size(); i++) {
if(users[i].first_name == user.first_name &&
users[i].last_name == user.last_name) {
return i;
}
}
users.push_back(user);
return users.size()-1;
}
int main() {
vector<User>users;
User user1, user2, user3;
user1.first_name = "Sally";
user1.last_name = "Swan";
user2.first_name = "Jake";
user2.last_name = "Johnson";
user3.first_name = "Larga";
user3.last_name = "Farad";
users.push_back(user1);
users.push_back(user2);
users.push_back(user3);
User user;
user.first_name = "Jake";
user.last_name = "Johnson";
cout << add_user_if_not_exists(users, user) << endl;
}
The output :
//Nothing
Yes, just nothing. When I type Enter, it just goes to the next line and does nothing. When I type a random word and hit Enter, it does nothing.
The IDE is Visual Studio Code. The OS is Ubuntu.
Aucun commentaire:
Enregistrer un commentaire