I just need help figuring out how to make sure the user enters a vaild value sin
ID: 3685867 • Letter: I
Question
I just need help figuring out how to make sure the user enters a vaild value since you can't have -1 tellers. Please someone help!
Write a C++ program that prompts the user for the number of tellers at Nation’s Bank in Fredonia that worked each of the last three years. For each worker the program should ask for the number of days out sick for each of the last three years. The output should provide the number of tellers and the total number of days missed by all the tellers over the last three years. Input Validation: It is important you ensure that the user enters a valid value for number of tellers!
Explanation / Answer
#include<iostream.h>
#include<iomanip.h>
using namespace std;
main() {
int t,y,d;
int total,i,j;
cout<<”Enter no of tellers:”;
cin>>t;
while(-1) {
if(t<0 || cin.fail()) {
cout << “Invalid input “;
cout << “Enter again:”;
cin>>t;
} else {
cout << “ Enter years:”;
cin>>y;
if(y!=3) {
cout <<”Enter again:”;
cin>>y;
} else {
cout<<”Enter no of days sick:”;
cin >>d;
}
for(i=1;i<=3;i++) {
total + = d; }
cout<<”No of Tellers at Bank:” <<t;
for(j=0;j<=t ;j++) {
cout << “No of days missed:” << total; }
}
}
}