Rewrite C program given by adding a conditional looping sta
Rewrite C++ program given ( by adding a conditional looping statement)
-Prompt user for their full name, if the name is XXXX, stop the program if not perform the task as it was describe in assignment 1. Your program must also print a final report including number of customer processed, total initial deposits, and total interest paid
#include <iostream>
#include <cmath>
using namespace std;
int main(){
// declaring variables
double principal;
double rate;
double year;
int num_of_times;
double interest;
bool valid = true;
string name;
// taking user input
cout<<\"Enter the name of depositor: \";
cin>>name;
cout<<\"Enter principal amount: \";
cin>>principal;
if(cin.fail())
{
valid = false;
}
cout<<\"Number of years: \";
cin>>year;
if(cin.fail())
{
valid = false;
}
cout<<\"How many number of time the interest is compounded per year :\";
cin>>num_of_times;
if(cin.fail())
{
valid = false;
}
cout<<endl<<\"-------------------------output-----------------------------------------------\"<<endl;
while(valid==false)
{
cout<<\"Program is stopped due to incorrect input Parameter \"<<endl;
return 0;
}
// getting rate value based on year value
if(year >= 5)
rate = 4.5;
else if(year >= 4)
rate = 4;
else if(year >= 3)
rate = 3.5;
else if(year >= 2)
rate = 2.5;
else if(year >= 1)
rate = 2;
else
rate = 1.5;
// calculating amount after year
double A= principal*pow(1+rate/(num_of_times*100), year*num_of_times);
interest = A - principal;
cout<<\"original deposit amount: $\"<<principal<<endl;
cout<<\"interest earned: $\"<<interest<<endl;
cout<<\"Amount of money accumulated after \"<<year<<\" years: $\"<<A<<endl;
return 0;
}
-Display the original deposit, the interest earned and the new Balance (with interested added to the deposit. The program should prompt user for the name of depositor, amount of deposit, number of times the interest is compounded per year, and years on deposit both as real numbers. Verify all inputted numbers are positive and not character, otherwise stop the program with an error message.
If a character instead of a number, stop the program.
If a negative number is entered, either prompt user for a correct one or print an error message and go to the next person. Do NOT stop the program.
Solution
#include <iostream>
#include <cmath>
#include <ctype>
using namespace std;
int main(){
// declaring variables
double principal;
double rate;
double year;
int num_of_times;
double interest;
boolean valid_A = true;
boolean valid_B = true;
string name;
int customer_count=0;
// taking user input
do
{
customer_count++;
cout<<\"Enter the name of depositor: \";
cin>>name;
if(name== \"XXXX\")
{
exit (EXIT_FAILURE);
}
cout<<\"Enter principal amount: \";
cin>>principal;
if(!isdigit(principal))
{
valid_A = false;
}
if(principal<0)
{
valid_B = false;
}
cout<<\"Number of years: \";
cin>>year;
if(!isdigit(year))
{
valid_A = false;
}
if(year<0)
{
valid_B = false;
}
cout<<\"How many number of time the interest is compounded per year :\";
cin>>num_of_times;
if(!isdigit(num_of_times))
{
valid_A = false;
}
if(num_of_times<0)
{
valid_B = false;
}
cout<<endl<<\"-------------------------output-----------------------------------------------\"<<endl;
if(valid_A==false)
{
cout<<\"Program is stopped due to incorrect input Parameter which may include a character \"<<endl;
exit (EXIT_FAILURE);
}
if(valid_B==false)
{
cout<<\"Please enter positive value for all the Inputted parameters\"<<endl;
valid_B==true;
}
}while(valid_B==true);
// getting rate value based on year value
if(year >= 5)
rate = 4.5;
else if(year >= 4)
rate = 4;
else if(year >= 3)
rate = 3.5;
else if(year >= 2)
rate = 2.5;
else if(year >= 1)
rate = 2;
else
rate = 1.5;
// calculating amount after year
double A= principal*pow(1+rate/(num_of_times*100), year*num_of_times);
interest = A - principal;
cout<<\"original deposit amount: $\"<<principal<<endl;
cout<<\"interest earned: $\"<<interest<<endl;
cout<<\"Amount of money accumulated after \"<<year<<\" years: $\"<<A<<endl;
cout<<\"Number of Customers processed \"<<customer_count<<endl;
return 0;
}



