Need help!!!

How would you set this up?

Each other time that the user gives a five digit number, give your number as follows: compute the difference of each digit of the user’s number with 9, and that is the number you will give. For example, if the user gives the number 12121, your number will be 87878 (so that when your number and the user’s number is added, the sum will be 99999).

So i prompt my user to enter a 5 digit number okay but how i do calculate the difference of each digit of the user number with 9 so that it appears in the output

for example if i enter 15555 how do i make it come out 84444?
Last edited on
You could do:
a = 99999
b = 12121 //the number user enters
c = a - b //the outcome

Hope this helps
I will help you with input validation because that can get tricky. Now you need to figure out how to loop through the input string and add 9 to each digit.

Feel free to ask questions.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>

using namespace std;
string getStringCheckForNumberAndLen();

int main() {
    string input = getStringCheckForNumberAndLen ();
    cout << input;
    return 0;

}

string getStringCheckForNumberAndLen() {
    bool goodinput = true;
    string input;
    while (goodinput) {
        bool badAlfaInput = false;
        cout << "Please enter in a nubmer" << endl;
        cin >> input;
        if (input.length () == 5) {
            for (auto &c : input) {
                if (isalpha (c)) {
                    badAlfaInput = true;
                }
            }
            goodinput = badAlfaInput;
            if (badAlfaInput) {
                cout << "Your input can only contain digits, please try again!!" << endl;
            }
        } else {
            cout << "Your input must be equal to 5 digits long, please try again!!" << endl;
        }

    }
    return input;
}

Last edited on
danielz thanks for the help but i just started c++ programming in college so im in begginner level and the code you have seems confusing or i havent gotten up to that level yet

and shinyspear i will try to take ur idea into account and find some way! thanks alot!
Topic archived. No new replies allowed.