1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
aleksley [76]
3 years ago
11

NO LINKS

Computers and Technology
1 answer:
horsena [70]3 years ago
3 0

Answer:

#include <iostream>

#include <string>

#include <regex>

using namespace std;

int main()

{

   cout << "Enter a 5-digit number: ";

   string number;

   cin >> number;

   bool valid = regex_search(number, regex("^\\d{4}[02468]$"));

   if (valid) {

       valid = stoi(number.substr(0, 1)) + stoi(number.substr(1, 1))  

           < stoi(number.substr(3, 1)) + stoi(number.substr(4, 1));

   }

   cout << number << (valid ? " is valid" : " is invalid");

}

Explanation:

Regular expressions can do all of your checking except for the sum of digits check. The checks are i.m.o. easiest if you don't treat the input as a number, but as a string with digits in it.

The regex means:

^ start of string

\d{4} exactly 4 digits

[02468] one of 0, 2, 4, 6 or 8 (this is what makes it even)

$ end of string

You might be interested in
A java program that calculates the balance of three months of $1000 and interest rate 6%
Mkey [24]

Answer: 60

Explanation: 1000 x 0.06 = 60.00

7 0
4 years ago
Stored information about a previous visit to a web site is called information _____.
Nikitich [7]
The answer would be Cookies.
6 0
3 years ago
Write. true or false​
ella [17]
Um I need a image or smth
8 0
3 years ago
Read 2 more answers
Create your own Python code examples that demonstrate each of the following. Do not copy examples from the book or any other sou
natulia [17]
Ssfhooiyfbjkoyfvhkodd
6 0
3 years ago
Derek has an interest in designing video games. What requirements should he fulfill to be a game designer?
dolphi86 [110]
Compooter science :D
3 0
3 years ago
Other questions:
  • Array testGrades contains NUM_VALS test scores. Write a for loop that sets sumExtra to the total extra credit received. Full cre
    10·1 answer
  • write an algorithm that gets the price for item A plus the quantity purchased. The algorithm prints the total cost, including a
    5·1 answer
  • The statement cout &lt;&lt; sales[0,3] + sales[1,3]; will __________. Use the following array named sales to answer this questio
    14·1 answer
  • Describe the characteristics of a mesh network.
    13·1 answer
  • Write a MATLAB script that prompts the user to input the following array by providing an example in the prompt: [2 4;6 3;5 9]. C
    15·1 answer
  • 3. Matthew captures traffic on his network and notices connections using ports 20, 22, 23, and 80. Which port normally hosts a p
    14·1 answer
  • Mr. Ray is looking for a platform to launch his product. His marketing team advises him to launch the product via as it is free
    15·2 answers
  • Which statement gives an advantage of multicellular organisms?
    7·2 answers
  • What can be changed when a style is modified?
    5·2 answers
  • Which of the following includes premium content you must pay to use?<br> On word
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!