6 Replies - 1341 Views - Last Post: 20 July 2012 - 05:07 AM Rate Topic: -----

#1 maskuman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 19-July 12

multiple menu problem in dev c++

Posted 19 July 2012 - 10:32 PM

got a problem here guys..
i want to create a code using multiple menus but im having a hard time
when i input the value for my first menu it also show the question for the second menu..
can you help me out..??


#include <iostream>
#include <iomanip>
#include <windows.h>
using namespace std;
int main()
{

   char choice;   

float ft,acre,lb,oz,gal,ton,in,mi;
float m,ha,kg,g,lit,mt,mm,km;
int select = 0;
int choose = 0;

   
 do
{   
cout<< endl<< endl<<setw(70)  << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
	<<setw(70)  << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl<< endl
	<<setw(70)	<< "~            The Metric and English Convertion            ~" << endl<< endl
	<<setw(70)	<< "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
	<<setw(70)	<< "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
	<<setw(70)	<< "                                                           " << endl
	<<setw(70)	<< "::::::::::::::::::::::INSTRUCTIONS:::::::::::::::::::::::::" << endl
	<<setw(70)	<< "                                                           " << endl
	<<setw(70)	<< "            Please Enter the Number of The Menu            " << endl
	<<setw(70)	<< "                                                           " << endl
	<<setw(70)	<< ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::" << endl<< endl
	<<setw(70)	<< "~~              a) English to Metric                     ~~" << endl
	<<setw(70)	<< "~~              B)/> Metric to English                     ~~" << endl<< endl
	<<setw(70)    << ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::" << endl<< endl
	<<setw(55)	<< "Please enter your choice [1 or 2]: ";
cin >> select; 
system("cls");

if (select == 1)
{
    
cout<< endl<< endl<<setw(70)  << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
	<<setw(70)  << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl<< endl
	<<setw(70)	<< "~            The English to Metric Convertion             ~" << endl<< endl
	<<setw(70)	<< "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
	<<setw(70)	<< "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
cout <<setw(57)<< "Please select from the following: " << endl<< endl;
cout <<setw(39)<< "1) Feet to Meter" << endl;
cout <<setw(42)<< "2) Acre to Hectares" << endl;
cout <<setw(44)<< "3) Pound to Kilograms" << endl;
cout <<setw(41)<< "4) Ounces to Grams" << endl;
cout <<setw(43)<< "5) Gallons to Liters" << endl;
cout <<setw(45)<< "6) Tons to Metric Tons" << endl;
cout <<setw(47)<< "7) Inches to Millimeters" << endl;
cout <<setw(45)<< "8) Miles to Kilometers" << endl<<endl;
cout <<setw(30)<< "Enter: ";
cin >> choose;
system("cls");
}
if (choose == 1)
{
     
cout<< endl<< endl<<setw(70)  << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
	<<setw(70)  << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl<< endl
	<<setw(70)	<< "~                      Feet to Meters                     ~" << endl<< endl
	<<setw(70)	<< "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
	<<setw(70)	<< "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
cout <<" Enter how many Feet: ";
cin >> ft;
m = ft*0.3048;
cout << "Equivalent in Meters is: " << m << endl;
}
else if (choose == 2)
{
     cout<< endl<< endl<<setw(70)  << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
	<<setw(70)  << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl<< endl
	<<setw(70)	<< "~                      Feet to Meters                     ~" << endl<< endl
	<<setw(70)	<< "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
	<<setw(70)	<< "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
cout <<" Enter how many Acres: ";
cin >> acre;
ha = acre*0.4046873;
cout << "Equivalent in Hectares is: " << ha << endl;
}
else if (choose == 3)
{
cout <<" Enter how many Pounds: ";
cin >> lb;
kg = lb*0.453592;
cout << "Equivalent in Kilograms is: " << kg << endl;
}
else if (choose == 4)
{
cout <<" Enter how many Ounces: ";
cin >> oz;
g = oz*28.34952;
cout << "Equivalent in Grams is: " << g << endl;
}
else if (choose == 5)
{
cout <<" Enter how many Gallons: ";
cin >> gal;
lit = gal*3.785412;
cout << "Equivalent in Liters is: " << lit << endl;
}
else if (choose == 6)
{
cout <<" Enter how many Tons: ";
cin >> ton;
mt = ton*0.9071847;
cout << "Equivalent in Metric Tons is: " << mt << endl;
} 
else if (choose == 7)
{
cout <<" Enter how many Inches: ";
cin >> in;
mm = in*25.4;
cout << "Equivalent in Millimeters is: " << mm << endl;
}
else if (choose == 8)
{
cout <<" Enter how many Miles: ";
cin >> mi;
km = mi*1.609347;
cout << "Equivalent in Kilometers is: " << km << endl;
}

else if(select == 2)
{
cout << "Please select from the following: " << endl;
cout << "1) Meter to Feet" << endl;
cout << "2) Hectares to Acres" << endl;
cout << "3) Kilograms to Pounds" << endl;
cout << "4) Grams to Ounces" << endl;
cout << "5) Liters to Gallons" << endl;
cout << "6) Metric Tons to Tons" << endl;
cout << "7) Millimeters to Inches" << endl;
cout << "8) Kilometers to Miles" << endl<<endl;
cout << "Enter: ";
cin >> choose;
system("cls");
}
if (choose == 1)
{
cout <<" Enter how many Meters: ";
cin >> m;
ft = m*3.28084;
cout << "Equivalent in Feet is: " << ft << endl;
}
else if (choose == 2)
{
cout <<" Enter how many Hectares: ";
cin >> ha;
acre = ha*0.4046873;
cout << "Equivalent in Acres is: " << acre << endl;
} 
else if (choose == 3)
{
cout <<" Enter how many Kilograms: ";
cin >> kg;
lb = kg*2.204623;
cout << "Equivalent in Pounds is: " << lb << endl;
} 
else if (choose == 4)
{
cout <<" Enter how many Grams: ";
cin >> g;
oz = g*0.035274;
cout << "Equivalent in Ounces is: " << oz << endl;
} 
else if (choose == 5)
{
cout <<" Enter how many Liters: ";
cin >> lit;
gal = lit*0.26417;
cout << "Equivalent in Gallons is: " << gal << endl;
} 
else if (choose == 6)
{
cout <<" Enter how many Metric Tons: ";
cin >> mt;
ton = mt*1.1023;
cout << "Equivalent in Tons is: " << ton << endl;
} 
else if (choose == 7)
{
cout <<" Enter how many Millimeters: ";
cin >> mm;
in = mm*0.039370;
cout << "Equivalent in Inches is: " << in << endl;
} 
else if (choose == 8)
{
cout <<" Enter how many Kilometers: ";
cin >> km;
mi = km*0.62137;
cout << "Equivalent in Miles is: " << mi << endl;
}
else 
cout << "ERROR ERROR ERROR ERROR ERROR" << endl;
cout << "Do you want to return to first page?? (y/n)";
cin>> choice;
system("cls");
}while (choice != 'n');
return 0;
}



Is This A Good Question/Topic? 0
  • +

Replies To: multiple menu problem in dev c++

#2 aresh  Icon User is offline

  • It's a 16-Bit World!
  • member icon

Reputation: 273
  • View blog
  • Posts: 4,176
  • Joined: 08-January 12

Re: multiple menu problem in dev c++

Posted 20 July 2012 - 01:25 AM

How about adopting a good indentation style? It will make your code easier to read and people will be more willing to help you.
Was This Post Helpful? 0
  • +
  • -

#3 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3629
  • View blog
  • Posts: 11,320
  • Joined: 05-May 12

Re: multiple menu problem in dev c++

Posted 20 July 2012 - 01:38 AM

I can't easily read your code right now, but my psychic powers tell me that you are using cin, and the data type you are reading into is a char. Something like:
char input1;
char input2;
cout << "Prompt for 1:" << endl;
cin >> input1;
cout << "Prompt for 2:" << endl;
cin >> input2;
cout << "Done." << endl;



And you never get a chance to enter a value for input2.

If you step through your code, you will find that input2 contains the '\n' character.

Perhaps regulars here will point the OP to past threads which discussed possible solutions to this "common" problem.
Was This Post Helpful? 0
  • +
  • -

#4 maskuman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 19-July 12

Re: multiple menu problem in dev c++

Posted 20 July 2012 - 02:00 AM

#include <iostream>
#include <iomanip>
#include <windows.h>
using namespace std;
int main()
{

char choice = 'n';   
float ft,acre,lb,oz,gal,ton,in,mi;
float me,ha,kg,gr,lit,mt,mm,km;
int select = 0;
int choose = 0;

   
 do
{   
cout<< endl<< endl<<setw(70)  << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
	<<setw(70)  << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl<< endl
	<<setw(70)	<< "~            The Metric and English Convertion            ~" << endl<< endl
	<<setw(70)	<< "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
	<<setw(70)	<< "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
	<<setw(70)	<< "                                                           " << endl
	<<setw(70)	<< "::::::::::::::::::::::INSTRUCTIONS:::::::::::::::::::::::::" << endl
	<<setw(70)	<< "                                                           " << endl
	<<setw(70)	<< "            Please Enter the Number of The Menu            " << endl
	<<setw(70)	<< "                                                           " << endl
	<<setw(70)	<< ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::" << endl<< endl
	<<setw(70)	<< "~~              a) English to Metric                     ~~" << endl
	<<setw(70)	<< "~~              B)/> Metric to English                     ~~" << endl<< endl
	<<setw(70)    << ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::" << endl<< endl
	<<setw(55)	<< "Please enter your choice [1 or 2]: ";
cin >> select; 
system("cls");

              if (select == 1)
              {
    
              cout<< endl<< endl<<setw(70)  << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
	          <<setw(70)  << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl<< endl
	          <<setw(70)	<< "~            The English to Metric Convertion             ~" << endl<< endl
	          <<setw(70)	<< "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
	          <<setw(70)	<< "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
              cout <<setw(57)<< "Please select from the following: " << endl<< endl;
              cout <<setw(39)<< "1) Feet to Meter" << endl;
              cout <<setw(42)<< "2) Acre to Hectares" << endl;
              cout <<setw(44)<< "3) Pound to Kilograms" << endl;
              cout <<setw(41)<< "4) Ounces to Grams" << endl;
              cout <<setw(43)<< "5) Gallons to Liters" << endl;
              cout <<setw(45)<< "6) Tons to Metric Tons" << endl;
              cout <<setw(47)<< "7) Inches to Millimeters" << endl;
              cout <<setw(45)<< "8) Miles to Kilometers" << endl<<endl;
              cout <<setw(30)<< "Enter: ";
              cin >> choose;
              system("cls");
              }
              
              
                            if (choose == 1)
                            {
                            cout <<" Enter how many Feet: ";
                            cin >> ft;
                            me = ft*0.3048;
                            cout << "Equivalent in Meters is: " << me << endl;
                            }
                            
                            
                            else if (choose == 2)
                            {
                               cout <<" Enter how many Acres: ";
                               cin >> acre;
                               ha = acre*0.4046873;
                               cout << "Equivalent in Hectares is: " << ha << endl;
                               }
                               
                               
                               else if (choose == 3)
                               {
                               cout <<" Enter how many Pounds: ";
                               cin >> lb;
                               kg = lb*0.453592;
                               cout << "Equivalent in Kilograms is: " << kg << endl;
                               }
                               
                               
                               else if (choose == 4)
                               {
                               cout <<" Enter how many Ounces: ";
                               cin >> oz;
                               gr = oz*28.34952;
                               cout << "Equivalent in Grams is: " << gr << endl;
                               }
                               
                               
                               else if (choose == 5)
                               {
                               cout <<" Enter how many Gallons: ";
                               cin >> gal;
                               lit = gal*3.785412;
                               cout << "Equivalent in Liters is: " << lit << endl;
                               }
                               
                               
                               else if (choose == 6)
                               {
                               cout <<" Enter how many Tons: ";
                               cin >> ton;
                               mt = ton*0.9071847;
                               cout << "Equivalent in Metric Tons is: " << mt << endl;
                               } 
                               
                               
                               else if (choose == 7)
                               {
                               cout <<" Enter how many Inches: ";
                               cin >> in;
                               mm = in*25.4;
                               cout << "Equivalent in Millimeters is: " << mm << endl;
                               }
                               
                               
                               else if (choose == 8)
                               {
                               cout <<" Enter how many Miles: ";
                               cin >> mi;
                               km = mi*1.609347;
                               cout << "Equivalent in Kilometers is: " << km << endl;
                               }



              if (select == 2)
              {
              cout << "Please select from the following: " << endl;
              cout << "1) Meter to Feet" << endl;
              cout << "2) Hectares to Acres" << endl;
              cout << "3) Kilograms to Pounds" << endl;
              cout << "4) Grams to Ounces" << endl;
              cout << "5) Liters to Gallons" << endl;
              cout << "6) Metric Tons to Tons" << endl;
              cout << "7) Millimeters to Inches" << endl;
              cout << "8) Kilometers to Miles" << endl<<endl;
              cout << "Enter: ";
              cin >> choose;
              system("cls");
              }
              
              
                            if (choose == 1)
                            {
                            cout <<" Enter how many Meters: ";
                            cin >> me;
                            ft = me*3.28084;
                            cout << "Equivalent in Feet is: " << ft << endl;
                            }
                            
                            
                            else if (choose == 2)
                            {
                            cout <<" Enter how many Hectares: ";
                            cin >> ha;
                            acre = ha*0.4046873;
                            cout << "Equivalent in Acres is: " << acre << endl;
                            } 
                            
                            
                            else if (choose == 3)
                            {
                            cout <<" Enter how many Kilograms: ";
                            cin >> kg;
                            lb = kg*2.204623;
                            cout << "Equivalent in Pounds is: " << lb << endl;
                            } 
                            
                            
                            else if (choose == 4)
                            {
                            cout <<" Enter how many Grams: ";
                            cin >> gr;
                            oz = gr*0.035274;
                            cout << "Equivalent in Ounces is: " << oz << endl;
                            } 
                            
                            
                            else if (choose == 5)
                            {
                            cout <<" Enter how many Liters: ";
                            cin >> lit;
                            gal = lit*0.26417;
                            cout << "Equivalent in Gallons is: " << gal << endl;
                            } 
                            
                            
                            else if (choose == 6)
                            {
                            cout <<" Enter how many Metric Tons: ";
                            cin >> mt;
                            ton = mt*1.1023;
                            cout << "Equivalent in Tons is: " << ton << endl;
                            } 
                            
                            
                            else if (choose == 7)
                            {
                            cout <<" Enter how many Millimeters: ";
                            cin >> mm;
                            in = mm*0.039370;
                            cout << "Equivalent in Inches is: " << in << endl;
                            } 
                            
                            
                            else if (choose == 8)
                            {
                            cout <<" Enter how many Kilometers: ";
                            cin >> km;
                            mi = km*0.62137;
                            cout << "Equivalent in Miles is: " << mi << endl;
                            }
                            
                            
      else 
      cout << "ERROR ERROR ERROR ERROR ERROR" << endl;
      cout << "Do you want to return to first page?? (y/n)";
      cin>> choice;
      system("cls");

}while (choice != 'n');
}






sorry my bad .. just indented it properly

im making a conversion program using two menu for english and metric system which has menu for both system

actually my main problem is that when i input the first value to calculate the problem for the first menu option, the second menu option shows..

example
the first problem in the first menu is to coonvert feet to meter after i entered the value and get the answer
the problem for the second menu pops out.
Was This Post Helpful? 0
  • +
  • -

#5 nuclearfroggy  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 82
  • View blog
  • Posts: 167
  • Joined: 04-August 08

Re: multiple menu problem in dev c++

Posted 20 July 2012 - 02:07 AM

If you indent your code with a consistent indentation style the problem should be clear. To see what I mean look for a pretty printer and run it through. Here's the program after running it through Visual studio's indenter:
#include <iostream>
#include <iomanip>
#include <windows.h>
using namespace std;
int main()
{

    char choice;   

    float ft,acre,lb,oz,gal,ton,in,mi;
    float m,ha,kg,g,lit,mt,mm,km;
    int select = 0;
    int choose = 0;


    do
    {   
        cout<< endl<< endl<<setw(70)  << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
            <<setw(70)  << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl<< endl
            <<setw(70)	<< "~            The Metric and English Convertion            ~" << endl<< endl
            <<setw(70)	<< "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
            <<setw(70)	<< "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
            <<setw(70)	<< "                                                           " << endl
            <<setw(70)	<< "::::::::::::::::::::::INSTRUCTIONS:::::::::::::::::::::::::" << endl
            <<setw(70)	<< "                                                           " << endl
            <<setw(70)	<< "            Please Enter the Number of The Menu            " << endl
            <<setw(70)	<< "                                                           " << endl
            <<setw(70)	<< ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::" << endl<< endl
            <<setw(70)	<< "~~              a) English to Metric                     ~~" << endl
            <<setw(70)	<< "~~              B)/> Metric to English                     ~~" << endl<< endl
            <<setw(70)    << ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::" << endl<< endl
            <<setw(55)	<< "Please enter your choice [1 or 2]: ";
        cin >> select; 
        system("cls");

        if (select == 1)
        {

            cout<< endl<< endl<<setw(70)  << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
                <<setw(70)  << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl<< endl
                <<setw(70)	<< "~            The English to Metric Convertion             ~" << endl<< endl
                <<setw(70)	<< "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
                <<setw(70)	<< "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
            cout <<setw(57)<< "Please select from the following: " << endl<< endl;
            cout <<setw(39)<< "1) Feet to Meter" << endl;
            cout <<setw(42)<< "2) Acre to Hectares" << endl;
            cout <<setw(44)<< "3) Pound to Kilograms" << endl;
            cout <<setw(41)<< "4) Ounces to Grams" << endl;
            cout <<setw(43)<< "5) Gallons to Liters" << endl;
            cout <<setw(45)<< "6) Tons to Metric Tons" << endl;
            cout <<setw(47)<< "7) Inches to Millimeters" << endl;
            cout <<setw(45)<< "8) Miles to Kilometers" << endl<<endl;
            cout <<setw(30)<< "Enter: ";
            cin >> choose;
            system("cls");
        }
        if (choose == 1)
        {

            cout<< eandl<< endl<<setw(70)  << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
                <<setw(70)  << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl<< endl
                <<setw(70)	<< "~                      Feet to Meters                     ~" << endl<< endl
                <<setw(70)	<< "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
                <<setw(70)	<< "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
            cout <<" Enter how many Feet: ";
            cin >> ft;
            m = ft*0.3048;
            cout << "Equivalent in Meters is: " << m << endl;
        }
        else if (choose == 2)
        {
            cout<< endl<< endl<<setw(70)  << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
                <<setw(70)  << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl<< endl
                <<setw(70)	<< "~                      Feet to Meters                     ~" << endl<< endl
                <<setw(70)	<< "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
                <<setw(70)	<< "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
            cout <<" Enter how many Acres: ";
            cin >> acre;
            ha = acre*0.4046873;
            cout << "Equivalent in Hectares is: " << ha << endl;
        }
        else if (choose == 3)
        {
            cout <<" Enter how many Pounds: ";
            cin >> lb;
            kg = lb*0.453592;
            cout << "Equivalent in Kilograms is: " << kg << endl;
        }
        else if (choose == 4)
        {
            cout <<" Enter how many Ounces: ";
            cin >> oz;
            g = oz*28.34952;
            cout << "Equivalent in Grams is: " << g << endl;
        }
        else if (choose == 5)
        {
            cout <<" Enter how many Gallons: ";
            cin >> gal;
            lit = gal*3.785412;
            cout << "Equivalent in Liters is: " << lit << endl;
        }
        else if (choose == 6)
        {
            cout <<" Enter how many Tons: ";
            cin >> ton;
            mt = ton*0.9071847;
            cout << "Equivalent in Metric Tons is: " << mt << endl;
        } 
        else if (choose == 7)
        {
            cout <<" Enter how many Inches: ";
            cin >> in;
            mm = in*25.4;
            cout << "Equivalent in Millimeters is: " << mm << endl;
        }
        else if (choose == 8)
        {
            cout <<" Enter how many Miles: ";
            cin >> mi;
            km = mi*1.609347;
            cout << "Equivalent in Kilometers is: " << km << endl;
        }

        else if(select == 2)
        {
            cout << "Please select from the following: " << endl;
            cout << "1) Meter to Feet" << endl;
            cout << "2) Hectares to Acres" << endl;
            cout << "3) Kilograms to Pounds" << endl;
            cout << "4) Grams to Ounces" << endl;
            cout << "5) Liters to Gallons" << endl;
            cout << "6) Metric Tons to Tons" << endl;
            cout << "7) Millimeters to Inches" << endl;
            cout << "8) Kilometers to Miles" << endl<<endl;
            cout << "Enter: ";
            cin >> choose;
            system("cls");
        }
        if (choose == 1)
        {
            cout <<" Enter how many Meters: ";
            cin >> m;
            ft = m*3.28084;
            cout << "Equivalent in Feet is: " << ft << endl;
        }
        else if (choose == 2)
        {
            cout <<" Enter how many Hectares: ";
            cin >> ha;
            acre = ha*0.4046873;
            cout << "Equivalent in Acres is: " << acre << endl;
        } 
        else if (choose == 3)
        {
            cout <<" Enter how many Kilograms: ";
            cin >> kg;
            lb = kg*2.204623;
            cout << "Equivalent in Pounds is: " << lb << endl;
        } 
        else if (choose == 4)
        {
            cout <<" Enter how many Grams: ";
            cin >> g;
            oz = g*0.035274;
            cout << "Equivalent in Ounces is: " << oz << endl;
        } 
        else if (choose == 5)
        {
            cout <<" Enter how many Liters: ";
            cin >> lit;
            gal = lit*0.26417;
            cout << "Equivalent in Gallons is: " << gal << endl;
        } 
        else if (choose == 6)
        {
            cout <<" Enter how many Metric Tons: ";
            cin >> mt;
            ton = mt*1.1023;
            cout << "Equivalent in Tons is: " << ton << endl;
        } 
        else if (choose == 7)
        {
            cout <<" Enter how many Millimeters: ";
            cin >> mm;
            in = mm*0.039370;
            cout << "Equivalent in Inches is: " << in << endl;
        } 
        else if (choose == 8)
        {
            cout <<" Enter how many Kilometers: ";
            cin >> km;
            mi = km*0.62137;
            cout << "Equivalent in Miles is: " << mi << endl;
        }
        else 
            cout << "ERROR ERROR ERROR ERROR ERROR" << endl;
        cout << "Do you want to return to first page?? (y/n)";
        cin>> choice;
        system("cls");
    }while (choice != 'n');
    return 0;
}

I'm guessing with the amount of nesting you just lost track, hopefully you can see now the control flow will not be what you expected. What you were probably trying was to put all the if (choose) clauses in a single block after being tested by the if (select == 0) i.e.
if (select == 0)
{
    if (choose = 0)
    {
         // code
    }
    else if (choose == 1)
    {
         // code
    }
    // and so on...
}
else if (select == 1)
{
    if (choose = 0)
    {
         // code
    }
    else if (choose == 1)
    {
         // code
    }
    // and so on again...
} 


You can also probably see that this is pretty nasty, especially once you've added another layer of nesting to get it to work. This is a prime example of where functions can be used to really make the code nicer. Split up the two different sets of inputs into their own function, maybe like metric_to_imperial() and imperial_to_metric(). Apart from just looking a lot nicer it will also reduce the chance of making mistakes like this one! Hopefully you have an idea of how to use functions, otherwise we can direct you to a tutorial.

Also, for long sets of if else's, the switch statement is useful. I'm not sure if you'll have covered it yet, and it's not essential, but it might be good to read up on it. For example, it would start to look more like
switch (choose)
{
case 1:
    // feet to meters stuff
    break;
case 2:
    // acres to hectares stuff
    break;
case 3:
    // pounds to kilograms stuff
    break;
default:
    // invalid input
    break;
} 
Also, one more side, maybe try and find better variable names than "choose" and "select", linguistically they're equivalent and pretty non-descriptive. Maybe like "conversion_type" and "unit_type" or something.

A bonus would then to make an enum with descriptive names like quantities, length, volumn, area, and so on instead of the numbers '0', '1', '2'. Again though this might be outside of the scope of what you know and so you could do a little research at some other point if you get the time. :)

Hope this helps.
Was This Post Helpful? 2
  • +
  • -

#6 maskuman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 19-July 12

Re: multiple menu problem in dev c++

Posted 20 July 2012 - 02:38 AM

thanks guys ima try that switch command thanks for the help ^^
Was This Post Helpful? 0
  • +
  • -

#7 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6081
  • View blog
  • Posts: 23,557
  • Joined: 23-August 08

Re: multiple menu problem in dev c++

Posted 20 July 2012 - 05:07 AM

Fixed nuclearfroggy's code for future reference:

if (select == 0)
{
    if (choose == 0)
    {
         // code
    }
    else if (choose == 1)
    {
         // code
    }
    // and so on...
}
else if (select == 1)
{
    if (choose == 0)
    {
         // code
    }
    else if (choose == 1)
    {
         // code
    }
    // and so on again...
} 


Was This Post Helpful? 1
  • +
  • -

Page 1 of 1