Ok i took a problem from the book where i had to write a progrm that will take how much is in yer bank account, wether you want to deposit or w/drawl, then checks yer new balance. It accepts capital and lowercase "W" and "D", but i want it to re-prompt for a transaction type when it gets a invalid type. Which it DOES but not till after it asks for the transaction amount:
Code:
//Program file chkbook.cpp
//This program updates a checkbook
//9-9-02
#include <iostream.h>
#include <iomanip.h>
int main ()
{
double startingbalance, endingbalance, transamount;
char transtype;
//Module for getting the data.
cout<<"Enter the Starting Balance abd press <enter>: ";
cin>>startingbalance;
cout<<"Enter the Transaction Type (D) Deposit or (W) Withdrawl ";
cout<<"And press <enter>: ";
cin>>transtype;
cout<<"Enter the transaction amount and press <enter>: ";
cin>>transamount;
//Module for performing computations.
if (transtype == 'D')
endingbalance = startingbalance + transamount;
else if (transtype == 'd')
endingbalance = startingbalance + transamount;
else if (transtype == 'W')
endingbalance = startingbalance - transamount;
else if (transtype == 'w')
endingbalance = startingbalance - transamount;
else
cout<<"Incorrect Transaction Type please re-enter "<<endl;
cout<<"Enter the Transaction Type (D) Deposit or (W) Withdrawl ";
cout<<"And press <enter>: ";
cin>>transtype;
//Module for displaying results
cout<<setiosflags(ios::fixed | ios::showpoint | ios::right)<<setprecision(2);
cout<<endl;
cout<<"Starting Balance $"<<startingbalance<<endl;
cout<<"Transaction $"<<transamount<<" "<<transtype<<endl;
cout<<"Ending Balance $"<<endingbalance<<endl;
return 0;
}