954,535 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Need help learning the loop/do while loop

so i'm stuck in creating a do/while menu doing this.

menu option 1 - use the for loop

menu option 2 - use the while loop

menu option 3 - use the do/while loop

in each option, print the numbers from 1 to 10

I made my functions like this. Anyone know how to do this?
the code on the bottom is just a example the teacher show us for do/while


[HTML]#include // needed for cin/count
#include // needed for math functions
using namespace std;

/****************************
* prototypes //declared function so main can find
*****************************/
void option01();

int main () // prototype to main
{
char option;
do
{
cout << " WYZ Company \n\n";
cout << " 1 - for loop \n\n";
cout << " 2 - while loop \n\n";
cout << " 3 - do while loop \n\n";
cout << " 4 - stuff01 \n\n";
cout << " 5 - stuff02 \n\n";
cout << " 9 - exit \n\n";
cout << "enter desired processing option here: [ ]\b\b";

cin >> option;

switch(option)
{
case '1': option01();
break;
case '2': cout << "you entered option 2\n";
break;
case '3': cout << "you entered option 3\n";
break;
case '4': cout << "you entered option 4\n";
break;
case '5': cout << "you entered option 5\n";
break;
case '9': cout << "we'er otta here\n";
break;
default: cout << "wrong code dummy\n";
} // end switch
}while(option != '9');
system("pause");
}
void option01()
{
cout << "you entered option 1\n";[/HTML]

jlouang
Newbie Poster
23 posts since Feb 2006
Reputation Points: 10
Solved Threads: 1
 

Just embed the switch statement to activate the menu choice within a do/while loop as indicated in the instruction

do
{
   //display menu
   switch(choice)
   {
       case 1: 
           //use for loop
           break
       case 2:
          //use while loop
          break
       case 3:
          //use do/while loop
          break
       case 6:
          //exit
       default
         //output information to user
     }//end switch
   }while (choice != 6)
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
 

I did it like this but it seems not to be working. anyone know the problem


[HTML]void option01();

int main () // prototype to main
{
char option;
do
{
cout << " WYZ Company \n\n";
cout << " 1 - for loop \n\n";
cout << " 2 - while loop \n\n";
cout << " 3 - do while loop \n\n";
cout << " 4 - stuff01 \n\n";
cout << " 5 - stuff02 \n\n";
cout << " 9 - exit \n\n";
cout << "enter desired processing option here: [ ]\b\b";

cin >> option;

do
{
//display menu
switch(option)
{
case 1: cout << "you entered option 1\n";
//use for loop
break;
case 2: cout << "you entered option 2\n";
//use while loop
break;
case 3: cout << "you entered option 3\n";
//use do/while loop
break;
case 6: cout << "you entered option 9\n";
//exit
default: cout << "wrong code dummy\n";
//output information to user
} //end switch
}while (choice != 6)
system("pause");
}
void option01()
{
cout << "you entered option 1\n";
}[/HTML]

jlouang
Newbie Poster
23 posts since Feb 2006
Reputation Points: 10
Solved Threads: 1
 

When you say something isn't working, it suggests that the code even compiles, which it doesn't. Does this work the way you expect?

#include <iostream>

using namespace std;

int main()
{
  int option;
  do
  {
    cout << "             WYZ Company\n\n";
    cout << "          1 - for loop\n\n";
    cout << "          2 - while loop\n\n";
    cout << "          3 - do while loop\n\n";
    cout << "          4 - stuff01\n\n";
    cout << "          5 - stuff02\n\n";
    cout << "          6 - exit\n\n";
    cout << "enter desired processing option here: [ ]\b\b";

    cin >> option;

    //display menu
    switch(option)
    {
    case 1: cout << "you entered option 1\n";
      break;
    case 2: cout << "you entered option 2\n";
      //use while loop
      break;
    case 3: cout << "you entered option 3\n";
      //use do/while loop
      break;
    case 6: cout << "you entered option 6\n";
      //exit
      break;
    default: cout << "wrong code dummy\n";
      //output information to user
      break;
    } //end switch
  }while (option != 6);
  system("pause");   
}
Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

Try using

int option;
WolfPack
Postaholic
Moderator
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
 

I need help to make
1 2 3
2 4 6
3 6 9
using for up to....
please help

ramti22
Newbie Poster
1 post since Nov 2009
Reputation Points: 10
Solved Threads: 0
 
I need help to make 1 2 3 2 4 6 3 6 9 using for up to.... please help

for (i=1; i<=3; i++) {
for (j=1; j<=3; j++) cout<

mISHOOO
Newbie Poster
4 posts since Sep 2009
Reputation Points: 10
Solved Threads: 0
 

i dont know when we use for loop, while , and do while , is there specific sitution when we use these.n our teacher learn us for this output 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.

for(int i=65;i<=90;i++)
cout << static_cast <char >(I)<<"  ";


here my qustiion is why we use thisfor(int i=65;i<=90;i++)statment for a b c d e................ make me clear plz

IT seeker
Light Poster
38 posts since Oct 2009
Reputation Points: 8
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You