切换语句... [英] Switch statement...

查看:99
本文介绍了切换语句...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该问题的伪代码为:
*从用户处获得初始余额;
*输入循环结构
*显示菜单
*从用户那里阅读菜单选项
*基于选择(开关或其他结构)
*根据以上选择执行代码以提取,存入或签发支票或退出* *结束循环
_____________________________
我的程序:

The pseudocode for the problem is:
*Get the inital balance from the user;
*Enter a loop structure
*display a menu
*read the menu choice from the user
*based on the choice (switch or if then else structure)
*execute the code to withdraw, deposit, or write a check, or quit, *based on the choice above
*end loop
_____________________________
My program:

#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;
//My name
//Lab XX XX
//December X, XXXX
//Write a program to help balance your money market checking account .
int main()
{
//User must enter the months opening account balance.
int account_balance = 0;                 

cout << "Enter months account balance:" ;
cin >> account_balance;    //need a semi colon at the end of each programming statement

//Program should display a menu to list following choices.
int following_choices ;
cout << "Enter following choices menu:" ;
double following_choices;  
cout << setprecision (2) << setiosflags (ios::fixed) << setiosflags (ios::showpoint);
cout << "Enter the account balance:'';
cin  >> "acount_balance;
cout << endl;
cout << "Enter the account balance according to the following" <<endl<<endl;
cout << "Deposit, enter D" << endl;
cout << "Check, enter C" <<endl;
cout << "Withdrawl enter W" <<endl;
cout << "Quit enter Q" << endl << endl;
cout << "Please make your selection.";
cin.get(); //Discard the \n
account_balance = cin.get();
switch (account_balance)
{
case ''D'':
case ''d'':
    account_deposit = ACCOUNT DEPOSIT;
        break;            //in this branch of the switch, you would ask the user for the amount deposted.
                            // you would then add it to your account balance variable.
case ''C'':
case ''c'':
    account_check = ACCOUNT CHECK;
        break;
case ''W'':
case ''w'':
    account_withdrawl = ACCOUNT WITHDRAWL
        break;
case ''Q'':
case ''q'':
    account_quit = ACCOUNT QUIT
        break;
default:
    cout << endl << endl << invalid account balance! "<<endl;
        exit (1);
    break:
}



它还没有完成,但是编译器说:案件后的未声明标识符;从C开始,依此类推.
它以"account _check" ...:confused:



it''s not finish but the complier says: undeclared identifier after the cases,; starting with C and so forth.
It starts with "account _check"...:confused:

推荐答案

开头.当然,编译器是正确的:未声明以下标识符(编程要求)语言):
The compiler is right, of course: the following identifiers are not declared (as required by the programming language):
account_deposit
account_withdrawl
account_quit


:)


写道:​​

cout<< 输入帐户余额:";
cin>> "acount_balance;

cout << "Enter the account balance:'';
cin >> "acount_balance;



那应该是:



That should have been:

cout << "Enter the account balance:";
cin  >> acount_balance;





写道:​​

cin.get(); //丢弃\ n
account_balance = cin.get();

cin.get(); //Discard the \n
account_balance = cin.get();



相反,您可以执行以下操作:



Instead, you could do this:

cout<<"Please make your selection"<<endl;
cin>>account_balance;





写道:​​

account_check = ACCOUNT CHECK;

account_check = ACCOUNT CHECK;





写道:​​

account_deposit =帐户存款;

account_deposit = ACCOUNT DEPOSIT;



什么是帐户支票",帐户存款"等,定义为?通过将此值分配给某个变量,您想完成什么工作?这没有任何意义.




What is ACCOUNT CHECK, ACCOUNT DEPOSIT, etc., defined as?! What are you trying to accomplish by assigning this value to some variable? This doesn''t make any sense.


写道:​​

cout<< endl<< endl<<无效的帐户余额! << endl;< blockquote =">

那应该是:

cout << endl << endl << invalid account balance! "<<endl;< blockquote="">

And that should be:

cout << endl << endl << "invalid account balance! "<<endl;



如果您需要澄清我的查询或提供更多信息,请使用此页面底部的留言板(单击新消息").



If you need to provide clarifications to my query or provide more information, use the message board at the bottom of this page (click on "New Message").


这篇关于切换语句...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆