WELL kiddies the other day i watched the move 'THE NUMBER 23' and i loved it so i wanted to know if my name was equal to the 23. So i created a little program did just that, and well my name does not equal 23. So try your luck kiddies:
*NOTE i started to comment on my codes, which i had never done before LOL
// This program calculates the value( in decimal form ) of a given word
// Word's Value
// By: Darwin Aguirre
#include <iostream> // library "iostream" for basic input/output
using std::cout; // user declaration for std::cout
using std::cin; // user declaration for std::cin
using std::endl; // user declaration for std::endl
using std::right; // user declaration for std::right
#include <iomanip> // library "iomanip" for manipulating input/output
using std::setw; // user declaration for std::setw
#include <cctype> // library "cctype" for C-style manipulation
#include <string> // library "string" for C++ style strings
using std::string; // user declaration for std::string
int CalculateValue( const string & ); // prototype function to determine value of word
void PrintInformation( const int &, const string & ); // prototype function to print information of the word
int main() // function main() to start the code
{ // start of main():
string Word; // variable of type string called Word
// introduction and details of the program
cout << "Welcome to this program, called \"Word's Value\".\n"
<< "What this program does is calculate the value"
<< "( in decimal form ) of a given word" << endl;
// instructions and promp
cout << "Please input a word that you would like to find the value of:" << endl;
Word.resize( 21 ); // resizeing the variable so data can be inserted
// setw( 21 ) specifies that cin should only read a max of 20 characters into
// Word and ignore the rest
cin >> setw( 21 ) >> Word;
// print the information of the word, notice that CalculateValue() is called
// as a argument for this function, so that it gets the value of the word
// via another function, also takes a string
PrintInformation( CalculateValue( Word ), Word );
// pause the system
system( "PAUSE" );
return 0; // return successful termination
} // ---------------
// definition of function CalculateValue()
int CalculateValue( const string &word )
{ // start of CalculateValue():
int value = 0; // variable of type int to store the word's value
// store the alphabet in an array so comparisons can be done
char Alpha[ 26 ] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
'y', 'z' };
// create all the characters lowercase if any( via loop ):
for ( size_t a = 0; a < word.size(); a++ ) {
// determine if the word is uppercase
if ( isupper( word.at( a ) ) == true ) {
// if so change it to lowercase
toupper( word.at( a ) );
}
}
// loop through all the elements of word to determine the value
for ( size_t i = 0; i < word.size(); i++ ) {
// loop the the alphabet to compare, then add
for ( int x = 0; x < 27; x++ ) {
// if they do match
if ( word.at( i ) == Alpha[ x ] )
value += ( x + 1 ); // add x + 1, because value += 0 don't work
} // end loop for alphabet
} // end loop for the word
return value; // return the value of the word
} // -------------------
// definition for function PrintInformation()
void PrintInformation( const int &Wvalue, const string &word )
{ // start of PrintInformation():
// set up a chart to display information
cout << "Word:" << setw( word.size() + 16 ) << right << "Value:" << endl;
// display the words information
cout << word << setw( word.size() + 11 ) << right << Wvalue << endl;
} // --------------
Post any words that equal 23 or whatever i dont care.