I am trying to make this program for my intro to c++ class. I have everything figured out except the bool to exit the do while loop. No matter if I put in y or n it loops forever all on its own. What am I missing?
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double days;
bool repeat = true;
int counter=1;
double pay=.01;
double runningTotal= 0.01;
do
{
cout << fixed << showpoint << setprecision(2);
cout<< "How many days did the employee work this month? ";
cin >> days;
while (days >31 || days < 1)
{
cout <<"Your input must be between 1 and 31." << endl ;
cout << "Try again: " ;
cin >> days ;
}
cout << "DAYS << setw(15) << endl ;
cout << "-------------------" << endl ;
cout << counter << setw(18) << pay;
cout << endl;
counter++;
Thanks Eyenrique but I still am not getting it... I switched it to a char and got it.
cout << "Do you want to try again? (Y/N) " ;
cin >> answer ;
while (answer != 'n' && answer != 'N' && answer != 'Y' && answer != 'y')
{
cout << "You must enter (Y/N): ";
cin >> answer;
}
}while (answer != 'n' && answer != 'N');
//percentage.cpp
//tip calculator
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
double getTipPercentage(double total);
int main(){
int total;
bool exit=false;
do{
cout<<"Enter total bill to calculate tip: ";
cin>>total;
cout<<"\nTotal :"<<total<<'\n'
<<"Tip: "<<getTipPercentage(total)<<endl;
cout<<"Do you want to try again? (0 zero to exit 1 continue)";
cin>>exit;
}while(exit);
return 0; //indicates success
}//end main
double getTipPercentage(double total){
double tip;
tip=total*0.20;
return tip;
}//end function getTipPercentage
Eyenrique-MacBook-Pro:Study Eyenrique$ ./percentage
Enter total bill to calculate tip: 120
Total :120
Tip: 24
Do you want to try again? (0 zero to exit 1 continue)1
Enter total bill to calculate tip: 120
Total :120
Tip: 24
Do you want to try again? (0 zero to exit 1 continue)0