I need to write a new code which can do the following:

Write a function-driven program that gives the new ID for a 4-digit integer entered from the keyboard.
The new ID is formed in the following procedure:
The last four digits of a social security number (SSN) will have a new digit for each.

The new digit for the first digit is figured out by timing it by 4;
if the product is greater than 9, add its digits together.
The new value for the second digit is figured out by timing it by 3.
if the product is greater than 9, add its digits together.
The new value for the third digit is figured out by timing it by 2.
if the product is greater than 9, add its digits together.
The new value for the fourth digit is figured out by timing it by 1.
If any of the new digits is 0, change it to 9.

All the four new digits are then added up to have a total, which is
then used to time to the entered 4-digit SSN to give the new encrypted ID.

For example, with the entered four digits 2620, the new ID will be 78600
because 2*4 = 8, 6*3 = 18 = 9, 2*2 = 4, 0*1 = 0 = 9, and 8+9+4+9 = 30,
and then 30*2620 = 78600.

/**************************
This Program Makes A New ID 
for the number entered by user.
***************************/
#include <iostream>

using namespace std;

int main()
{
	char code[4];
	int ssn;
	bool valid = false;
	
	do 
	{
        valid = false;
		cout << "Enter 4 Digit Code:  ";
		cin >> code;
		for (int i = 0; i<strlen(code);i++)
		{
			if (code[i] >3 || code[i] <5) 
			{
				valid = true;
				fflush(stdin);
				break;
			}
		}
	} while (valid == true);

	fflush(stdin);
	cin.get();
	return 0;
}

The above is what I have started. There is a problem as well, because a user can only use 4 characters, anything above or below 4 characters must be rejected, but this one rejects anything you throw at it. Anyone know the problem?

hey dude so many errors in compilation itself
write header file with .h xtension
n add stdio, string.h
no data type as boolean in c+
it seems u use java

@OP

You are recieving it as characters.
So, when you type 1, its acutally taken as: '0' + 1

Use an integer array. or subtract '0' after taking input. i guess that was the problem. Does it solve it?

Edited 6 Years Ago by myk45: n/a

This article has been dead for over six months. Start a new discussion instead.