小编The*_*mer的帖子

循环失败

我需要让程序循环,直到用户输入"XXXX"作为名称.问题是,我的代码最多只循环一次并退出.我已经尝试过做一整天......而且似乎无法解决这个问题,但我觉得我真的很亲密!

编辑: 你们真棒!做了两个更改但现在它跳过了名称提示并直接进入存款提示.如何让它在循环中包含名称提示?

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

int main() {

string name, XXXX;
float deposit, time, interest, total, totinterest;
int compound;

cout << left;

int flag = 0;

do {

    cout << "Enter your name or XXXX to stop: ";
    getline(cin, name);
    cout << name << " enter the following information: " << endl;


    if (name == "XXXX"){
        flag = 1;
    }else 
    {

        cout << setw(60) << "\tAmount on deposit: ";
        cin >> deposit;
        if …
Run Code Online (Sandbox Code Playgroud)

c++ visual-c++

2
推荐指数
2
解决办法
84
查看次数

标签 统计

c++ ×1

visual-c++ ×1