#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
string num1, num2;
int size, decimalCounter = 0;
bool decimalFound1 = false, decimalFound2 = false, goodInput = false;
int main(void){
char word[81];
do{
bool palindrome=true;
int ShowMainMenu();
void oneone(), onetwo();
void twoone(), twotwo();
void threeone(), threetwo();
int choice, subchoice, out;
int main();
{
//actual calculations
if (choice == 1 && subchoice == 1)
oneone();
else if (choice == 1 && subchoice == 2)
onetwo();
else if (choice == 2 && subchoice == 1)
twoone();
else if (choice == 2 && subchoice == 2)
twotwo();
else if (choice == 3 && subchoice == 1)
threeone();
cout << "Press (enter) key to end";
fflush (stdin);
cin.get();
}
int ShowMainMenu();
{
int choice;
cout << "1: Palindeome\n";
cout << "2: Compare Two Integers\n";
cout << "3: End program\n";
while ( !(cin >> choice) || choice <= 0 || choice > 3)
{
cout << "Error invalid choice try again.\n";
}
return choice;
}
cout << "Please enter a word" << endl;
cin>>word;
int length = strlen(word);
for (int i=0; i<length; i++){
word[i] = toupper(word[i]);
}
int(length/2);
if (length>0){
for(int i=0;i<(length);i++)
{
if(word[i]!=word[length-1-i])
palindrome=false;
}
}
if(palindrome==true)
{
cout << "The word is a palindrome" << endl;
}
else
{
cout << "The word is not a palindrome" << endl;
}
} while (0 != strcmp(word, "END"));
return(0) ;
}
int main()
{
string num1, num2;
int size, decimalCounter = 0;
bool decimalFound1 = false, decimalFound2 = false, goodInput = false; //These are to indicate whether we found a decimal place in the number
cout << "Please enter the first number: ";
cin >> num1;
cout << "Please enter the second number: ";
cin >> num2;
//Find the smallest size number
if(num1.size() > num2.size())
size = num2.size();
else
size = num1.size();
for(int i = 0; i < size; ++i)
{
if(isdigit(num1[i]) && isdigit(num2[i])) { goodInput = true;}
if( (isdigit(num1[i]) && num2[i] == '.' ) && decimalFound2 == false) { goodInput = true; decimalFound2 = true; }
if( (isdigit(num2[i]) && num1[i] == '.' ) && decimalFound1 == false) { goodInput = true; decimalFound1 = true;}
if( (num1[i] == '.' && num2[i] == '.' ) && ( decimalFound1 == false && decimalFound2 == false)) { decimalFound1 = true; decimalFound2 = true;}
//If the input was verified to be good, check and see if they are the same, if so, increment the decimal counter
if(goodInput == true && num1[i] == num2[i])
++decimalCounter;
//reset the good input variable
goodInput = false;
}
cout << "\n\nThere were exactly " << decimalCounter << " similar digits in your two numbers.";
//Pause the program
cin.sync();
cin.get();
return 0;
}
This post has been edited by jimblumberg: 20 March 2013 - 12:51 PM
Reason for edit:: Added missing code tags. Please learn to use them properly.

New Topic/Question
Reply



MultiQuote



|