Looping

Hello guys, please assist me as to how I can get my code to prompt the user to enter the correct integer(choice) and actually allow him to select the correct choice

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
int choice;
double FV, PV, k, n;

cout << "Select your choice\n";
cout << "1-COMPOUND\n";
cout << "2-NET PRESENT VALUE\n";
cin >> choice;

if (choice == 1)
{
double PV = 0;
double n = 0;
double k = 0;
double FV = 0;

char choice;
cout << "WHAT DO YOU WANT TO CALCULATE?\n";
cout << "a-Future Value (FV)\n";
cout << "b-Present Value (PV)\n";
cout << "c-Period Interest Rate (k)\n";
cout << "d-Number of Compounding Periods (n)\n";
cin >> choice;
switch (choice)
{
case 'a':

cout << "Enter Present Value\n";
cin >> PV;
cout << "Enter Interest Rate\n";
cin >> k;
cout << "Enter Number of Compounding Periods\n";
cin >> n;

FV = PV * pow((1 + k), n);
cout << "Future Value = P " << FV << endl;
break;

case 'b':

cout << "Enter Future Value\n";
cin >> FV;
cout << "Enter Interest Rate\n";
cin >> k;
cout << "Enter Number of Compounding Periods\n";
cin >> n;

PV = FV / pow((1 + k), n);

cout << "Present Value = P " << PV << endl;
break;

case 'c':

cout << "Enter Future Value\n";
cin >> FV;
cout << "Enter Present Value\n";
cin >> PV;
cout << "Enter Number of Compounding Periods\n";
cin >> n;

k =( pow((FV / PV), 1 / n)) - 1;

cout << "Period Interest Rate = " << k << endl;
break;

case 'd':

cout << "Enter Future Value\n";
cin >> FV;
cout << "Enter Present Value\n";
cin >> PV;
cout << "Enter Period Rate Interest\n";
cin >> k;

n = log(FV/PV)/log(1+k);

cout << "Number of Compound Period = " << n <<" years"<< endl;
}
}

else
if (choice == 2)
{
char choice;
cout << "a-Net Present Value for one Project\n";
cout << "b-Net Present Value for Projects Evaluation\n";
cin >> choice;
}
else
{
int choice;
cout << "Invalid Selection!\n";
cout << "Please Enter a valid choice\n";
cout << "1-COMPOUND\n";
cout << "2-NET PRESENT VALUE\n";
cin >> choice;
}

}
Topic archived. No new replies allowed.