/* The Necklace Sum up 1st and 2nd digit, then the sum's last digit is displayed. Repeats the process until the previous digit and the current digit are equal to the first and 2nd digit respectively */ #include // Note this is an old program, iostream.h is deprecated, use instead int main() { int First, Second, ResultDigit, PrevDigit, steps, Sum; cout << "Enter first digit: "; cin >> First; cout << "Enter second digit: "; cin >> Second; if(First > 9 || Second > 9) { cout << "The first and second numbers are supposed to be digits, which is less than 10."; return(0); } Sum = (First+Second); ResultDigit = Sum%10; PrevDigit = Second; steps = 1; while ((PrevDigit != First) || (ResultDigit != Second)) { steps++; Sum = ResultDigit + PrevDigit; PrevDigit = ResultDigit; ResultDigit = Sum%10; cout << " " << ResultDigit; } cout << "\nThe number of steps taken was " << steps << endl; return(0); }