菜单驱动器输入DO循环
Menu Drive Input Do Loop
我需要为我的编程类创建菜单驱动的输入[案例/开关语句]。我的教授还没有教我们如何创建菜单,而我很难理解我的教科书。我需要菜单循环,直到用户选择退出以终止程序为止。我还需要一条错误消息,其中包括案例/开关中的默认值,错误消息必须描述错误由用户引起。
有人可以指导我做什么吗?我只需要开始,其余的通常对我来说是自然的。
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
ofstream ofs("bafia_lab5.txt");
string msg = "eofmessage ";
string cno = "blank ";
string name = "blank ";
string dat = "2/16/17 ";
string lab = "blank ";
string phn = "blank ";
string sum = "Create menu that allows users to choose between While Loop, Do Loop, For Loop and quit. ";
string whlo = "While Loop:";
string dooo = "Do While Loop:";
string forro = "For While Loop";
int counter;
int option;
//Header for lab with name, class#, due date, and lab number
void hdr()
{
ofs << name << cno << dat << lab << endl;
ofs << endl;
}
void menu()
{
do
{
ofs << "1. Do Loop " << dooo << endl;
ofs << "2. While Loop " << whlo << endl;
ofs << "3. For Loop" << forro << endl;
ofs << "4. Quit " << endl;
ofs << endl;
} while (option <= 4)
}
//Function for "while loop"
void whl()
{
ofs << whlo << endl;
counter = 1;
while (counter <= 10)
{
ofs << counter << endl;
counter++;
}
ofs << endl;
}
//Function for "do while loop"
void doo()
{
ofs << dooo << endl;
counter = 1;
do
{
ofs << counter << endl;
counter++;
} while (counter <= 10);
ofs << endl;
}
//Function for "for loop"
void forr()
{
ofs << forro << endl;
for (counter = 1; counter <= 10; counter++)
{
ofs << counter << endl;
}
ofs << endl;
}
//Function for description of lab
void ftr()
{
ofs << sum << endl;
ofs << endl;
}
//End of file function with name, class#, due date, and lab number
void eof()
{
ofs << msg << name << cno << dat << lab << endl;
}
//Call all functions
int main()
{
hdr();
menu();
whl();
doo();
forr();
ftr();
eof();
return 0;
}
您可以做这样的事情:
char choice = 'y';
while(choice == 'y' || choice == 'Y'){
cout << "Enter choice : ";
cin >> choice;
switch(choice) {
case 'a' : cout << "This is case-an";
//do something
break;
...
default : //invalid choice alert
break;
}
cout << "Enter y/Y to continue else anything else to exit : ";
cin >> choice;
}
相关文章:
- 如果条件为TRUE(最佳方式?),则在do while循环中后置增量
- 即使没有满足他们的条件,我也无法通过一些 do-while 循环
- 如何使用 do while 循环确定最高值和最低值
- do while 循环中的 if 语句以 yes 或 no 结尾
- 在 C 或 C++ 中,循环可以同时具有 "do" 和"while"部分吗?
- 使用 while 或 do while 退出循环
- 带有开关语句的 do-while 循环 -- 无穷循环错误
- 为什么当我输入一个被接受的数字时,我的 do-while 循环没有中断?
- 为什么我的 Do-while 循环无法在C++中运行菜单
- 如果语句不会在 do - while 循环中运行
- 为什么当我对数组使用增量操作时,do for 循环不起作用
- 如何在c++中读取do-while循环中的空白
- 将嵌套的 for 循环更改为 do-while 循环
- 如何修复不会在退出选择时终止的 do-while 循环
- 带有do函数的无限循环
- 为什么这个do-while循环每隔一个循环只写入数组?
- C++ do/while 循环和 if/else: 骰子游戏 -- 第 75 行错误:"Cout"之前的预期"While" -- 如何解决这个问题?
- 卡在链表中的无限 Do-while 循环中
- 试图调节我的 do-while 以停止在终端中退出程序.菜单不会根据需要循环使用当前语句
- 使用基本 do-while 循环求解泊松方程