27-11-2013, 23:41
|
|
|
חבר מתאריך: 19.01.04
הודעות: 705
|
|
הצלחתי להגיע למשהו שנותן לי את התוצאה המתאימה, אשמח אם תוכלו לתת דעה ולתת הצעות לשיפור, בעיקר של ה"עימוד" והנראות של הקוד.
קוד:
#include <iostream>
#include <string>
using namespace std;
void main()
{
{
string name; // User will enter is name
cout << "Please enter your name : \n";
cin >> name;
}
int ID, sum, counter = 1; // The int. that the progrem will use
bool wrong_ID = true; // The bool is for the progrem to know when to stop
do
{
cout << "Please enter your ID number : \n";
cin >> ID; // user enter is ID number
sum = 0;
while (ID > 0)
{ // The algorithm of the progrem
int i = (ID % 10);
ID = ID / 10;
int j = (ID % 10) * 2;
int x = j % 10;
int y = j / 10;
sum = sum + i + x + y;
ID = ID / 10;
}
if (sum % 10 == 0)
wrong_ID = false;
else
cout << "The ID number you typed is illegal \n";
counter++; // user have only 3 opportunities
} while (wrong_ID && counter <= 3);
if (wrong_ID)
cout << "You typed illegal ID number for too many times \n";
else
cout << "Your account is now open! \n";
}
_____________________________________
"I love the smell of napalm in the morning"
|