I have no intention of doing your homework
However, here are some ideas to get you started.
I have left out how to do the reducing algo. You do this since
this is the most important part of the program.
/************************************************** ****
A program by treenef to calculate the magic
number of a person's name
************************************************** ****/
Code:
#include <iostream>
#include <string.h>
#include <math.h>
#include <ctype.h>
int sub_prog(int);
int reduce_to_digit_sum(int);
using namespace std;
int main()
{
char name[81];
cout<<"Enter a name:";
cin.getline(name,81); //use cin.getline to account for white spaces
int size_of=strlen(name);
//Convert Capital to lower case
for (int a=0; a<size_of; a++)
{
name[a]=(char)tolower(name[a]);
}
char alaphabet[28]={"/abcdefghijklmnopqrstuvwxyz"};
int num=0;
for (int a=0; a<size_of; a++)
{
for (int b=1; b<27; b++)
{
if (name[a]==alaphabet[b])
{
num=num+b; // accumulate
}
}
}
cout<<num;
int stop;
cin>>stop;
// call function sub prog send num into it
sub_prog(num);
int pause;
cin>>pause;
}
//function declaration
int sub_prog(int digit_sum)
{
if (digit_sum>=10)
{
//call function reduce to digit sum
//passing 'digit_sum' into it
reduce_to_digit_sum(digit_sum);
}
else
cout<<"Your magic number is: "<<digit_sum;
}
//function declaration
int reduce_to_digit_sum(int digit_sum)
{
//128
//1+2+8 =11 =>send this to sub_prog
// This is the algorithm that you need to think up
// No more help.
// Tip use the modulus function '%'
// Note:If I do this for you then I am effectively doing
// your homework!!! :)
sub_prog(digit_sum); // looping back to sub_prog
}