/*This program is a short source code for the already created numbers 
program.  This program uses functions, while the previous version does 
not.

Version 1.1 

http://willjasen.vze.com  */

#include <iostream>
#include <string>
using namespace std;

void repeat();

int main()
{
    int total, num1, num2;
    int i, x=10, y=20, z=1; 
    cout << "Choose a number 1 - 9\n";
    cout << "Now double it\n";
    cout << "Now add 5\n";
    cout << "Now multiply it by 5\n";
    cout << "Now choose a different number 1 - 9 and add it on\n";
    cout << "What is your total \n";
    cin >> total;
    total -= 25;
    for(i=1; i<11; i++) {
        if ((x<total) && (total<y)) {
            num1=z; x=1;
        }    
        else {
            x+=10; y+=10; z+=1;
        }
    }  
    z=1;  
    for(i=1; i<10; i++) {
        if((total-x)%10==0) {
            num2=z;
        }
        else {
            x+=1; z+=1;
        }
    }    
    cout << "The first number you picked was: " << num1 << endl;
    cout << "The second number you picked was: " << num2 << endl;
    repeat();
    
    return 0;
}

void repeat()
{
    char answer;
    cout << "Would you like to try again?  Type 'y' for yes and 'n' for no. \n";
    cin >> answer;
    switch(answer) {
    case 'y' : main(); break;
    case 'n' : cout << " "; break;
    default : repeat();
    }
}