c++ - 询问帐户类型两次

标签 c++

从事这个项目已有一段时间了。 (有一些问题,在这里问了几次。)但是遇到了另一个问题!该程序两次询问我的帐户类型。无法弄清楚为什么或如何解决它。感谢任何帮助,谢谢!

    /*
project3.cpp
Andre Fecteau
CSC135-101
October 29, 2013
This program prints a bank's service fees per month depending on account type
*/

#include <iostream>
using namespace std;
/*
Basic Function for Copy Paste
<function type> <function name> (){

// Declarations
// Initalizations
// Input
// Process
// Output
// Prolouge
}
*/

void displayInstructions (){
// Declarations
// Initalizations
// Input
// Process
// Output
cout <<"| -------------------------------------------------------------- |" << endl;
cout <<"| ---------- Welcome to the bank fee calculator ---------------- |" << endl;
cout <<"| -------------------------------------------------------------- |" << endl;
cout <<"| This Program wil ask you to eneter your account number.        |" << endl;
cout <<"| Then it will ask for your account type Personal or Commercial. |" << endl;
cout <<"| Then ask for the amount of checks you have written.            |" << endl;
cout <<"| Lastly it will output how much your fees are for this month.   |" << endl;
cout <<"| -------------------------------------------------------------- |" << endl;
cout << endl;
// Prolouge
}

int readAccNumb(){
  // delarations
  int accNumber;
  // intitalizations
  accNumber = 0.0;
  // input
  cout << "Please Enter Account Number:";
  cin >> accNumber;
  // Procesas
  // output
  // prolouge
  return accNumber;
}

int checksWritten (){
// Declarations
int written;
// Initalizations
written = 0.0;
// Input
cout <<"Please input the amount of checks you have written this month:";
cin >> written;
// Output
// Prolouge
return written;
}

char accType (){
// Declarations
char answer;
int numberBySwitch;
// Initalizations
numberBySwitch = 1;
// Input
while (numberBySwitch == 1){
    cout << "Please Enter the acount type (C for Comerical and P for Personal):";
    cin >> answer;
// Process
switch (answer){
    case 'p':
        answer = 'P';
        numberBySwitch += 2;break;
    case 'P':
        numberBySwitch += 2;break;
    case 'c':
        answer = 'C';
        numberBySwitch += 3;break;
    case 'C':
        numberBySwitch += 3;break;
    default:
        if(numberBySwitch == 1) {
        cout << "Error! Please enter a correct type!" <<endl;
        }
    }
}
// Output
// Prolouge
return answer;
}

int commericalCalc(int checksWritten){
// Declarations
int written;
int checkPrice;
// Initalizations
checkPrice = 0.0;
// Input
// Process
if(written < 20){
    checkPrice = 0.10;
}
// Output
// Prolouge
return checkPrice;
}

int personalCalc(int checksWritten){

}

double pricePerCheck(char accType, int checksWritten){
// Declarations
double price;
char answer;
// Initalizations
price = 0.0;
// Input
// Process
if(accType == 'P'){
}
if(accType == 'C'){
    if(checksWritten < 20){
        price = 0.10;
    }
}
// Output
// Prolouge
return price;
}

int main(){
  // Declarations
  int accountNumb;
  char theirAccType;
  int writtenChecks;
  double split;
  // Initalizations
  accountNumb = 0.0;
  writtenChecks = 0.0;
  split = 0.0;
  theirAccType = ' ';
  // Input
  displayInstructions();
  theirAccType = accType();
  accountNumb = readAccNumb();
  split = pricePerCheck(accType(), checksWritten());
  // Output
cout << endl;
cout << "Account Type: " << theirAccType << endl;
cout << "Check Price: " << split << endl;
  // Prolouge
 return 0;
}

最佳答案

theirAccType = accType();
...
split = pricePerCheck(accType(), checksWritten());
//                    ^^^^^^^^^

您正在第二次调用 accType。您应该在第一行传入用于保存初始调用的变量。

split = pricePerCheck(theirAccType, checksWritten());
//                    ^^^^^^^^^^^^

关于c++ - 询问帐户类型两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19869042/

相关文章:

使用类 T 的 C++ 函数指针

C++ 派生类覆盖构造函数值更改

c++ - 提交快照时删除 SVN 中丢失的文件

c++ - 创建具有最小深度的二叉搜索树

c++ - 在 C++ 环境中使用 OpenCV 绘制边界框

c++ - 将 CDialog 转换为 CPropertyPage

C++ 编译器错误

c++ - 如何将 UTF-8 编码的 std::string 转换为 UTF-16 std::string

c++ - MFC 对话框中的 QWinWidget 不重新绘制或响应 Tab/箭头键

c++ - 以下代码不会对 Stdout 做出任何响应