2 Replies - 1221 Views - Last Post: 20 March 2013 - 03:36 PM Rate Topic: -----

#1 jigsaw786  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 25-February 13

Menu-Driven Program

Posted 20 March 2013 - 11:15 AM

so the problem i have is how to put these two programs together as a driven menu?

#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.


Is This A Good Question/Topic? 0
  • +

Replies To: Menu-Driven Program

#2 jigsaw786  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 25-February 13

Re: Menu-Driven Program

Posted 20 March 2013 - 11:27 AM

ohh to be more clear thats what i am trying to do

Write a menu-driven program that allows users do two options:
Option 1: It can tell whether a word, phrase, or sentence entered at the keyboard is a palindrome,
which is spelled the same in backward as well as in forward.
All punctuation characters should not be counted in the calculation for the palindrome.
Option 2: It compares two positive integers entered at the keyboard and returns the number of
decimal places (i.e. the ones, tens, hundreds place, and so on) that have the same digit.
Validate your input values: do not accept character(s) and negative and/ or floating-point values.
Was This Post Helpful? 0
  • +
  • -

#3 Adak  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 331
  • View blog
  • Posts: 1,168
  • Joined: 01-April 11

Re: Menu-Driven Program

Posted 20 March 2013 - 03:36 PM

Run through a C tutorial, and learn how functions work. What you've got is code from somebody else, which you have no idea of how to work with it.

Programming is work, and you can't learn to program that way.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1