Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8865811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:36:50+00:00 2026-06-14T16:36:50+00:00

This c++ program I have been working on is generating runtime errors that involve

  • 0

This c++ program I have been working on is generating runtime errors that involve the following:

1.generatePass method skips validation process.

2.validatePass method skips user input and also skips validation.

I’m new to c++,is there some sort of nextLine method to add to user input like in java and any ideas as to why validation is being skipped.A different perspective would help as I haven’t found anything else so far.

Thanks,Brian.

#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include <windows.h>
#include <ctime>
#include <string.h>
#include <time.h>


using namespace std;
#define MAX 80


//declaring functions
int showMenu();     
void generatePass();    
void validatePass();
int countLetters(char *,int *,int *,int *,int *,int *);





int main()
{

    int iChoice;

    // have menu appear, user makes decision, do work, reshow menu
    // do this until user enters 5

    do
    {

        iChoice = showMenu();


    }while(iChoice != 3);

    printf("\n\n\n");
    system("pause");


}//end of main

//Methods placed here:

//showMenu method calls program menu,either 1.generate password,2.enter password and validate. or 3.exit(close program)
int showMenu()
{
    int iChoice;

    system("cls");
    printf("\n\n\t\tWelcome to Password Generator and Validator\n\n");
    printf("\n\t\t1. Generate");
    printf("\n\t\t2. Validate");
    printf("\n\t\t3. Exit");

    printf("\n\n\t\tEnter your menu choice: ");
    fflush(stdin);
    scanf_s("%d", &iChoice);

    // user enters one of 3 values
    // generate,validate or exit program


    switch(iChoice)
    {
        case 1:     // generate
        {
            generatePass();

            break;
        }
        case 2:     // validate
        {
            validatePass();


            break;
        }
        case 3:     // exit
        {
            printf("\n\nProgram exiting!...");

            break;
        }
        default:
        {
            break;
        }
    }//end of switch


    return(iChoice);
} //end of showMenu


//method to generate a random password for user following password guidelines.  
void generatePass()

{

    int iChar,iUpper,iLower,iSymbol,iNumber,iTotal;

    printf("\n\n\t\tGenerate Password selected ");
    printf("\n\n\t\tPassword creation in progress... ");

    int i;
    char password[10 + 1];
    char strLower[59+1] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRTUVWXYZ!£$%^&*";


    srand(time (0));

    for(i = 0; i < 10;i++)
    {
        password[i] = strLower[(rand() % 52)];

    }
    password[i] = '\0';


    iChar = countLetters(password,&iUpper,&iLower,&iSymbol,&iNumber,&iTotal);

    if(iUpper < 2)
    {
        printf("Not enough uppercase letters!!!\n");


    }
    else if(iLower < 2)
    {
        printf("Not enough lowercase letters!!!\n");


    }
    else if(iSymbol < 1)
    {
        printf("Not enough symbols!!!\n");


    }
    else if(iNumber < 2)
    {
        printf("Not enough numbers!!!\n");


    }
    else if(iTotal < 9 && iTotal > 15)
    {
        printf("Not enough characters!!!\n");


    }
    printf("\n\n\n Your new password is verified ");
    printf(password);


    printf("\n\n\n");
    system("pause");



}//end of generatePass method.








//method to validate a user generated password following password guidelines.
void validatePass()
{

    char password[MAX+1];
    int iChar,iUpper,iLower,iSymbol,iNumber,iTotal;

    //shows user password guidelines
    printf("\n\n\t\tPassword rules: ");
    printf("\n\n\t\t 1. Passwords must be at least 9 characters long and less than 15 characters. ");
    printf("\n\n\t\t 2. Passwords must have at least 2 numbers in them.");
    printf("\n\n\t\t 3. Passwords must have at least 2 uppercase letters and 2 lowercase letters in them.");
    printf("\n\n\t\t 4. Passwords must have at least 1 symbol in them (eg ?, $, £, %).");
    printf("\n\n\t\t 5. Passwords may not have small, common words in them eg hat, pow or ate.");

    //gets user password input
    printf("\n\n\t\tEnter your password following password rules: ");
    gets_s(password);


    iChar = countLetters(password,&iUpper,&iLower,&iSymbol,&iNumber,&iTotal);

    if(iUpper < 2)
    {
        printf("Not enough uppercase letters!!!\n");


    }
    else if(iLower < 2)
    {
        printf("Not enough lowercase letters!!!\n");


    }
    else if(iSymbol < 1)
    {
        printf("Not enough symbols!!!\n");


    }
    else if(iNumber < 2)
    {
        printf("Not enough numbers!!!\n");


    }
    else if(iTotal < 9 && iTotal > 15)
    {
        printf("Not enough characters!!!\n");


    }
    printf("\n\n\n Your new password is verified ");
    printf(password);


    printf("\n\n\n");
    system("pause");


}//end validatePass method

int countLetters(char * Password,int * Upper,int * Lower,int * Symbol,int * Number,int * Total)
{
    int iTotal = 0,iC = 0,tU = 0,tL = 0,tS = 0,tN = 0;


    //strlen- function that returns length
    for (int iC = 0;iC < strlen(Password);iC++)
    {

        printf("%d",Password[iC]);
        //uppercase letters are in the range 65 - 90
        //lowercase letters are in the range 97 - 122
        //symbols are in the range 32-48
        //numbers are in the range 47 - 58


        if((Password[iC] < 64) && (Password[iC] < 91))
        {
            tU++;
            iTotal++;

        }
        else if((Password[iC] > 96) && (Password[iC] < 123))
        {
            tL++;
            iTotal++;

        }
        else if((Password[iC] > 32) && (Password[iC] < 48))
        {
            tS++;
            iTotal++;

        }
        else if((Password[iC] > 47) && (Password[iC] < 58))
        {
            tN++;
            iTotal++;

        }

        *Upper = tU;/*set value at memory address = tU,passing by reference saves memory used.*/
        *Lower = tL;
        *Symbol = tS;
        *Number = tN;


    }//end for statement


    return (iTotal);
}//end of countLetters
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T16:36:51+00:00Added an answer on June 14, 2026 at 4:36 pm

    I think the primary problem is that while you have the building blocks, you haven’t sufficiently kept up with planning your design. Don’t worry, it’s fixable.

    1.generatePass method skips validation process.

    generatePass() performs the validation within itself, but you might want to put these lines…

    printf("\n\n\n Your new password is verified ");
    printf(password);
    

    …into an else block so that the user doesn’t think the password was okay when it wasn’t. You also probably want to leverage the validatePass() function in generatePass(), as you’re currently repeating code.

    2.validatePass method skips user input and also skips validation.

    Perhaps this link is relevant to the problem you’re having with gets_s(): StackOverflow.com. In any event, you can use scanf for the time being, because it’ll make things easier at first, and you can go back later and make your program more robust if you need to. Scanf will fix the input being bypassed. Validation being skipped is the same pattern as #1, so if you figure out what you want to do for that, it’ll be easy here.

    I’m not sure I understand the Java nextLine() question, but using scanf with %s to read a string functions roughly similar to the Java Scanner.nextLine().

    Disclaimer: I ran your program as a C program, since it was trivial to convert it from C++ to C. (I suppose if you’re going to write in C-style code, you might consider just making it a C program. Similarly, you could opt to avoid Windows-only stuff (e.g., the ‘_s’ functions) if you want the program to be more portable, but you may be getting some good utility out of those ‘_s’ functions before you’re done, so it’s only an idea.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this program that I am working on for class, I think the
I have been working on a quick WinForms program. I found this SO question
I have been working on this program but everytime I attempt to build, I
I have been working on a program that will enable me to monitor which
I have been working on this program for a while and I finally got
I have been working on this program for quite sometime and my brain is
i am new kernel programming.i have been trying to load this driver program for
I have this program that should execute a piece of code base on the
I have this program, but cin in randomly skips.. I mean sometimes it does,
I have been working in a big program and one of its functionalities should

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.