256 Kilobytes

Answers in Software Development | By Some Guy

Published | Last Update

2,253 views, 0 RAMs, and 1 comment

Tags: C++, Java, Passcode, Programming Language

Profile Photo - Some GuySome GuyBasic Subscriber

I am working on a C++ function. I need help on setting a variable called hasDigitt to true if the 3 character value/variable passCode has a digit. Can anyone help me on this?

Download more RAM. 🐏 ⨉ 0Posted by Some Guy 2 years ago

Edit History

• [2018-12-16 9:28 PST] Some Guy (2 years ago)
🕓 Posted at 16 December, 2018 09:28 AM PST

This is a debug account.

Profile Photo - August R. GarciaAugust R. GarciaLARPing as a Sysadmi...Portland, ORSite Owner

This is a bad question (from a C++ textbook -- "ZyBook CSCI 40") and you should feel bad, but this is one possible answer:

// Set hasDigit to true if the 3-character passCode contains a digit.

#include <string>
#include <cctype>

using namespace std;

// A function that returns true if the string passed into it contains one or more digits
bool has_digit(string &passCode) {
    for( unsigned int iii = 0; iii < passCode.size(); ++iii)
       if (  isdigit(passCode[iii])  )
           return true;
    return false;
}

// Main loop, obviously
int main() {
    // Depending on what you're trying to do, plausibly read in some user input here
    string passCode = "abc";

    bool hasDigit = has_digit(passCode);
    
    // Plausibly do something with hasDigit here

    return 0;
}

If you're here trying to get answers to your shitty homework, you should drop out of college.

Download more RAM. 🐏 ⨉ 0Posted by August R. Garcia 2 years ago

Edit History

• [2019-03-06 9:04 PST] August R. Garcia (2 years ago)
• [2019-03-06 9:04 PST] August R. Garcia (2 years ago)
🕓 Posted at 06 March, 2019 09:04 AM PST

Sir, I can do you a nice SEO.

Post a New Comment

Do you like having a good time?

Register an Account

You can also login to an existing account or reset your password. All use of this site is subject to the terms of service and privacy policy.

Read Quality Articles

Read some quality articles. If you can manage to not get banned for like five minutes, you can even post your own articles.

View Articles →

Argue with People on the Internet

Use your account to explain why people are wrong on the Internet forum.

View Forum →

Vandalize the Wiki

Or don't. I'm not your dad.

View Wiki →

Ask and/or Answer Questions

If someone asks a terrible question, post a LMGTFY link.

View Answers →

Make Some Money

Hire freelancers and/or advertise your goods and/or services. Hire people directly. We're not a middleman or your dad. Manage your own business transactions.

Register an Account

Answers— Read More

Find more related content below!