#Please help , why its not working ?

97 messages · Page 1 of 1 (latest)

safe sierraBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

hallow notch
#

Please help , why its not working ?

velvet saffron
#

you need to have qualifiers for functions from the standard library

#

so cout should be std::cout

#

and so on

hallow notch
#

naa dont use libray its a requiremnt

#

if the customer have already rented a car and want to rent another car so i wanted him to buy a car not give his imformation again , i need this to happen

velvet saffron
#

cout, string, cin are from the standard library that comes with c++

hallow notch
#

the logic is not working

velvet saffron
#

alright, so you have using namespace std; somewhere?

hallow notch
#

yes yes bruh

#

if the customer have already rented a car and want to rent another car so i wanted him to buy a car not give his imformation again , i need this to happen

velvet saffron
#

have you tried debugging?

hallow notch
#

yeah

#

its not working

velvet saffron
#

so uuh, could you post the context code?

#

because from the code you posted it looks like you're comparing entered_name == registered_name when registered name is empty

hallow notch
#

ok

#

but then i am comparing it to name

#

when user registerd his name

velvet saffron
#

string registered_name=""; will make registered_name empty every time you go through that line

hallow notch
#

oh then what should i do

velvet saffron
#

you should specify what you want the program to do more exactly

#

like is this code meant to just be in main()?

#

or in a loop

hallow notch
#

i want it to store name

#

seee

#

see rentcar function

hallow notch
#

you find something ?

slow rivet
#

what's the expected output and what's the actual output

#

and what user input are you giving

hallow notch
#

expected output is that if the user first registered himself he has not to registerd again to rent a car

upper dock
hallow notch
#

what check ?

upper dock
hallow notch
#

how to do that i dont understand

upper dock
hallow notch
#

yeah yeah

upper dock
# hallow notch yeah yeah

So you want the program to remember who's registered after it's ended (terminated)
and when you run it again?

#

Wanna be sure

hallow notch
#

yeah for sure

upper dock
# hallow notch yeah for sure

Then you have three options

  1. Easiest: Text file that stores a line for each user
  2. Kinda easy: JSON file that stores users
  3. Hardest but robust: Database
hallow notch
#

oops

#

any other option

upper dock
#

I wouldn't recommend 3 for small projects

upper dock
#

it's pretty much that

hallow notch
hallow notch
upper dock
upper dock
hallow notch
upper dock
#

use a std::vector<std::string>
store First name + Last name
on new user register check if First name + Last name already exists in the vector

#

Tho I'd suggest a more robust way like this

hallow notch
#

i dont use vector

upper dock
#
struct Customer {
    std::string first_name;
    std::string last_name;
    int ssn;
};
upper dock
hallow notch
#

ok this will work

#

struct then ?

upper dock
hallow notch
#

yeah yeah

upper dock
#

Well yeah just do this too

#
struct customer {
    std::string first_name;
    std::string last_name;
    int ssn;
    bool operator == (customer& other) {
        return ssn == other.ssn;
    }
};
#

ssn is always unique

#

first name + last name isn't

hallow notch
#

first name is enougth

#

tbh

upper dock
#

Up to you

hallow notch
#

ok then ?

upper dock
# hallow notch ok then ?

on each input, check if this array of customer (or std::string if you wanna) already has this value or not

#

if it doesn't

#

then just add it to the array

#

heads up, you can't increase an array size

#

make sure you use a reasonable number

hallow notch
#

its pretty hard tho

#

i have done this with rent car and avalible cars but there i use bool isrented like this

upper dock
#

You just loop through the array elements

#

And check if element is equal to first name given to you

hallow notch
#
void rentCar(int id)
    {
        node *temp = head;
        while (temp != NULL)
        {
            if (temp->carid == id)
            {
                if (temp->isRented)
                {
                    cout << "Car is already rented" << endl;
                    return;
                }
                else
                {
                    temp->isRented = true;
                    string name, mobileno;
                    bool isregis = false;
                    if (!isregis)
                    {
                        cout << "ENter your name : ";
                        cin >> name;
                        cout << "Enter your phoneno : ";
                        cin >> mobileno;
                    }
                    else
                    {
                        // isregis = true;
                        cout << "You are already registerd member";
                        // return;
                    }
                    cout << "Car rented successfully" << endl;
                    total_cars--;
                    return;
                }
            }
            temp = temp->next;
        }
        cout << "Invalid car ID" << endl;
    } 
```cpp
upper dock
#

are you using a linked list?

hallow notch
#

yeah

#

single

upper dock
#

queue might help with that

#

instead of doing this yourself

hallow notch
#

ok how ?

upper dock
#

or a deque

hallow notch
#

ok will try to do this

#

thanks for the help

safe sierraBOT
#

@hallow notch Has your question been resolved? If so, run !solved :)

hallow notch
#

yyeah kinda !solved

#

!solved

safe sierraBOT
#

Thank you and let us know if you have any more questions!