Answer to Question #304579 in C++ for Mansi

Question #304579

A company is planning to provide an extra discount to it's customers. Every order has an order ID associated with it which is a sequence of digits. The discount is calculated as the count of unique repeating digits in the order ID. Write a code to find the discount percentile given to the customers.

1
Expert's answer
2022-03-01T14:00:12-0500
#include <iostream>
using namespace std;

int main() {
    int customer;
    int discount=0;
    int digits[10] = {0,0,0,0,0,0,0,0,0,0};

    cin >> customer;
    
    while (customer > 0) {
        digits[customer%10]++;
        customer /= 10;
    }

    for (int i = 0; i < 10; i++) {
        if (digits[i] >= 2) {
            discount++;
        }
    }
    cout << discount << endl;

    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog