Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. help me write a program

help me write a program

Scheduled Pinned Locked Moved C / C++ / MFC
help
14 Posts 8 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Jochen Arndt

    Please read the sticky post (actually) just above yours: HOW TO ASK A QUESTION - C / C++ / MFC Discussion Boards[^]

    Quote:

    Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.

    Quote:

    If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums

    You won't get code written for you here. Just try it yourself and tell us where you got stuck. Then we will try to help.

    U Offline
    U Offline
    User 12936170
    wrote on last edited by
    #4

    ok sir...

    1 Reply Last reply
    0
    • U User 12936170

      write a program that can be enter the password , if the correct password,the output will display "Your password is correct" if not the output will display "Your password is incorrect" and prompted to re enter a password. this is my code but i still cant figure out what its prolblem.:confused::confused: #include int main() { int password=12345; printf("Please insert your password:\n"); scanf("%p" , &password); if(password=12345); { printf("Your password is correct"); } if else(password!=12345); { printf("Your password is incorrect"); } } its say error expected '(' before 'else'.. kindly anybody can help me..please..

      S Offline
      S Offline
      Stefan_Lang
      wrote on last edited by
      #5

      Member 12968703 wrote:

      its say error expected '(' before 'else'..

      The error message already told what is the problem: just read it and check the code that it points out, in this case the else statement: that particular line is incorrect and needs fixing.

      GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)

      1 Reply Last reply
      0
      • U User 12936170

        write a program that can be enter the password , if the correct password,the output will display "Your password is correct" if not the output will display "Your password is incorrect" and prompted to re enter a password. this is my code but i still cant figure out what its prolblem.:confused::confused: #include int main() { int password=12345; printf("Please insert your password:\n"); scanf("%p" , &password); if(password=12345); { printf("Your password is correct"); } if else(password!=12345); { printf("Your password is incorrect"); } } its say error expected '(' before 'else'.. kindly anybody can help me..please..

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #6

        scanf("%p" , &password); // should be %d for integer values

        if(password=12345); // should be '==' for comparison test
        {
        printf("Your password is correct");
        }

        if else(password!=12345); // Removed the 'if', this is a continuation of the previous if statement

        R 1 Reply Last reply
        0
        • L Lost User

          scanf("%p" , &password); // should be %d for integer values

          if(password=12345); // should be '==' for comparison test
          {
          printf("Your password is correct");
          }

          if else(password!=12345); // Removed the 'if', this is a continuation of the previous if statement

          R Offline
          R Offline
          Rick York
          wrote on last edited by
          #7

          Also remove the semicolons following the right parens.

          L 1 Reply Last reply
          0
          • R Rick York

            Also remove the semicolons following the right parens.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #8

            :doh:

            R 1 Reply Last reply
            0
            • L Lost User

              :doh:

              R Offline
              R Offline
              Rick York
              wrote on last edited by
              #9

              I mean the right parens on the lines with ifs. The one on this line :

              if(password=12345);

              Will cause the printf to always execute.

              L 1 Reply Last reply
              0
              • R Rick York

                I mean the right parens on the lines with ifs. The one on this line :

                if(password=12345);

                Will cause the printf to always execute.

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #10

                I know, hence my :doh: , indicating my stupidity.

                U 1 Reply Last reply
                0
                • U User 12936170

                  write a program that can be enter the password , if the correct password,the output will display "Your password is correct" if not the output will display "Your password is incorrect" and prompted to re enter a password. this is my code but i still cant figure out what its prolblem.:confused::confused: #include int main() { int password=12345; printf("Please insert your password:\n"); scanf("%p" , &password); if(password=12345); { printf("Your password is correct"); } if else(password!=12345); { printf("Your password is incorrect"); } } its say error expected '(' before 'else'.. kindly anybody can help me..please..

                  P Offline
                  P Offline
                  Patrice T
                  wrote on last edited by
                  #11

                  if else(password!=12345);

                  You need to learn better the if-else structure.

                  Patrice “Everything should be made as simple as possible, but no simpler.” Albert Einstein

                  1 Reply Last reply
                  0
                  • L Lost User

                    I know, hence my :doh: , indicating my stupidity.

                    U Offline
                    U Offline
                    User 12936170
                    wrote on last edited by
                    #12

                    #include int main() { float number = 123456; int pass; printf("Please enter your password:\n"); scanf("%d",&pass); if (pass==number) { printf("Your password is correct.\n"); } else { printf("Your password is incorrect.\n"); } } i already write the program but i dont know how to make a prompted to re enter a password if i enter a wrong password..i really dont know..and i hope u can help me..

                    L D 2 Replies Last reply
                    0
                    • U User 12936170

                      #include int main() { float number = 123456; int pass; printf("Please enter your password:\n"); scanf("%d",&pass); if (pass==number) { printf("Your password is correct.\n"); } else { printf("Your password is incorrect.\n"); } } i already write the program but i dont know how to make a prompted to re enter a password if i enter a wrong password..i really dont know..and i hope u can help me..

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #13

                      You do it be creating a loop, using a do, while or for statement. In pseudo code something like:

                      Set a retry count
                      While retry is not zero
                      Check password
                      If password is correct
                      Then break
                      Else
                      retry = retry - 1
                      If retry is zero
                      Then display error message
                      End While

                      See if you can turn that into C code.

                      1 Reply Last reply
                      0
                      • U User 12936170

                        #include int main() { float number = 123456; int pass; printf("Please enter your password:\n"); scanf("%d",&pass); if (pass==number) { printf("Your password is correct.\n"); } else { printf("Your password is incorrect.\n"); } } i already write the program but i dont know how to make a prompted to re enter a password if i enter a wrong password..i really dont know..and i hope u can help me..

                        D Offline
                        D Offline
                        David Crow
                        wrote on last edited by
                        #14

                        Member 12968703 wrote:

                        if (pass==number)

                        Comparing an int to a float will rarely, if ever, work.

                        Member 12968703 wrote:

                        but i dont know how to make a prompted to re enter a password if i enter a wrong password..i really dont know..and i hope u can help me..

                        To continue the prompting until the correct password is entered, you'll need to use a loop. Something like:

                        do
                        {
                        ...
                        } while (password != 12345);

                        "One man's wage rise is another man's price increase." - Harold Wilson

                        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                        "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups