-1

So basically the issues is that it doesn't register the user input like it should per ex: I enter the right password and username, and it still does the while loop and Int Tries doesn't go up after every int Tries.

PS: int Cooldown doesn't have any purpose yet, the code is not finished

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main() {
    char user[] = "";
    char password[] = "";
    bool ifnotcorrect;
    int Tries = 0;
    int Cooldown;

    printf("Enter UserName: ");
    scanf("%s", &user);

    printf("Enter Password: ");
    scanf("%s", &password);

    if (user == "Vaxaop" || password == "1234") {
        ifnotcorrect = false;
        printf("loggin you in...(the code is finished lol)");
    }

    if (user != "Vaxaop" || password != "1234")
        ;
    {
        printf(
            "Wrong usernamer or password try again! Tries: %d. Warning After 3 "
            "tries There is a cooldown of 60s \n",
            Tries++);

        while (ifnotcorrect = true) {
            printf("Enter UserName: ");
            scanf("%s", &user);

            printf("Enter Password: ");
            scanf("%s", &password);

            if (user == "Vaxaop" || password == "1234") {
                ifnotcorrect = false;
                printf("loggin you in...(the code is finished lol)");
            }
        }
    }

    return 0;
}
David Makogon
  • 67,251
  • 21
  • 140
  • 181
Vaxaop
  • 11
  • 1
  • 1
    These declarations char user[] = ""; char password[] = ""; do not make a sense. They declare arrays with one element. – Vlad from Moscow May 18 '22 at 17:57
  • 2
    `user` and `password` can only hold an empty string because of how they are declared. You should set a siza when declaring them like `char user[128] = "";` You can't compare strings with `==` and `!=`, you need to use `strcmp`. Since you're passing an array to `scanf` you should rewove the `&` in front of the variable name. `||` should be `&&` in the first if assuming both the username and password need to be correct. – Retired Ninja May 18 '22 at 17:57
  • 1
    @Vaxaop This if statement if(user == "Vaxaop" || password == "1234") also does not make a sense. At least you should write if( strcmp( user, "Vaxaop" ) == 0 && strcmp( password, "1234" ) == 0 ) – Vlad from Moscow May 18 '22 at 18:00
  • @Vaxaop In this while loop while(ifnotcorrect = true){ there is used the assignment operator instead of comparison. So the program has so many errors that it does not make a sense to discuss it. Read at first a book on C for beginners. – Vlad from Moscow May 18 '22 at 18:03
  • @Vaxaop You need at first to read a book on C for beginners. – Vlad from Moscow May 18 '22 at 18:11
  • 1
    @Vaxaop Look for example here https://stackoverflow.com/questions/562303/the-definitive-c-book-guide-and-list – Vlad from Moscow May 18 '22 at 18:19
  • If tl;dr, this [strcmp man page](https://pubs.opengroup.org/onlinepubs/009604499/functions/strcmp.html) has an example very much like what you are trying to do. – Neil May 18 '22 at 18:39
  • 1
    @Neil Thank you so much man you saved my little programme lol – Vaxaop May 19 '22 at 19:34

0 Answers0