C++ const Account createAccount(); – It will prompt the user for the account nam
ID: 3902014 • Letter: C
Question
C++
const Account createAccount();
– It will prompt the user for the account name, interest rate, and starting balance in that order
– The prompts shall appear as follows: Let's set up your account. First, what's the name of the account? What is the interest rate of your [NAME] account? Finally, what is the starting balance of your [NAME] account?
– You may NOT assume that the name of the account contains only a single word – You may assume the user will always type an interest rate as a decimal value (e.g. 0.05) – The user is allowed to type their amount of money with or without a ‘$’
I just need help with the user inputing the balance of the account and skip the $ char.
Explanation / Answer
#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
const Account createAccount()
{
char acc_name[50]; // Variable for account name
float int_rate,start_bal; //Variables for interest rate and starting balance
int i;
char bal[20]; // variable for accepting the balance woth $ sign
cout<<endl<<"Let's set up your account";
cout<<endl<<"First, what's the name of the account?";
gets(acc_name);
cout<<endl<<"What is the interest rate of your "<<acc_name<<" account?";
cin>>int_rate;
cout<<endl<<"Finally, what is the starting balance of your "<<acc_name<<" account?";
cin>>bal; // Storing the balance with $ sign or without $ sign into bal
if(bal[0]=='$') // checks whether $ sign is available with balance or not
{
for(i=0;bal[i]!='';i++)
{
bal[i]=bal[i+1]; // logic for removing the $ sign from the balance
}
}
start_bal=atof(bal); // converting the balance into floating point value
//cout<<endl<<acc_name;
//cout<<endl<<int_rate;
//cout<<endl<<"Amount "<<start_bal;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.