试图建立一个数组来存储过去三年存款存入银行账户体系 [英] Trying to setup an array to store the last three deposits into bank account system

查看:184
本文介绍了试图建立一个数组来存储过去三年存款存入银行账户体系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

float deposit (float balance)
{
    float amount[3]; 
    system("cls");
    cout<<"Enter the amount you wish to deposit"<<endl; 
    cin>>amount[3]; 
        balance = balance + amount[3]; 
    writeBalance(balance); 
    return balance;  
}
//This is a function to allow the user to increase their balance 

但是当我在节目中的存款部分输入量的弹出框出现并说:

but when I enter an amount in the deposit section of the program a popup box comes up and says:

Run-Time Check Failure #2 - Stack around the variable 'amount' was corrupted.

任何帮助将是巨大的感谢

any help would be great thanks

推荐答案

您必须输入一个循环数组中的每个元素。更改code以下方式

You must enter each element of the array in a loop. Change the code the following way

float deposit (float balance)
{
    const size_t N = 3; 
    float amount[N]; 
    system("cls");
    cout<<"Enter the amount you wish to deposit"<<endl;

    for ( size_t i = 0; i < N; i++ )
    { 
        cin>>amount[i]; 
        balance = balance + amount[i];
    }

    writeBalance(balance); 
    return balance;  
}

虽然实际上没有必要使用的阵列。你可以在一个常规的变量输入数据。

Though in fact there is no need to use the array. You could enter data in one regular variable.

这篇关于试图建立一个数组来存储过去三年存款存入银行账户体系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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