two separate issues one return error the other validation problem.

I want to put in Validation to only allow the account number to be 4 digits ONLY
Program ALLOWS less than 4 digits. I am not able to find what the problem is. Have read and looked everywhere to find an answer but no success. Can someone clue me in please. Also I have an ERROR id returned 1 exit status and don't have a clue how to fix that. Checked the last line several times and not able to get rid of the error.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
  #include <iomanip>
#include <cstring>
#include <iostream>
#include <sstream>
#include <math.h>
#include <cstdlib>
using namespace std;

int main()
{
	int accNo;
	string consultDate;
	double treatmentFee;
	double initialPay;
	double balDue;
	double monthlyPay;
	int conDate[3];
	int tempDate[3];
	int noOfpayments;
	double totalPaid;
	double outstBal;
	
	
	
		do{
			cout <<"Please Enter Patient Account No: ";
			cin >> accNo;
		}while (accNo>9999);
		
		//validate the patient account no
		
		cout <<"Enter Consultation Date: ";
		cin >>consultDate;
		istringstream ss(consultDate);
		string token;
	
		for(int i=0;i<3;i++)
		{
		std::getline(ss, token, '/');
		conDate[i]=atoi(token.c_str());
		tempDate[i]=atoi(token.c_str());
		}
		//get the date as a user input and split and store it in array
		//so to access each element
		
		cout << "Enter Treatment fee: ";
		cin >> treatmentFee;
		cout << "Enter Initial Payment: ";
		cin >> initialPay;
		totalPaid = initialPay;
		balDue = treatmentFee-initialPay;
		outstBal = balDue;
		
		cout << "Enter Monthly Payment: ";
		cin >> monthlyPay;
		noOfpayments = balDue/monthlyPay;
		
		//get other user inputs
		
		if ((fmod(balDue,monthlyPay)) > 0.0)
		//checking whether there is a remainder when divided into equal monthly pay units	
		{
			noOfpayments++; //if there is a remainder increment the no of inputs
		}
		
		cout << string(50, '\n');   //clean the screen
		
		cout << "PATIENT ACCOUNT NUMBER: "<<accNo<<endl;
		cout << "CONSULTATION DATE: "<<consultDate<<endl;
		cout << "\n\n";
		cout << "TREATMENT FEE: $ "<<treatmentFee<<endl;
		cout << "INITIAL PAYMENT: "<<initialPay<<endl;
		cout << "BALANCE DUE: "<<balDue<<endl;
		cout << "\n\n";	
		
		//print header	
		
		cout << "PAYMENT\tDUE\tPAYMENT\tTOTAL\tOUTSTANDING\n";
		cout << "NUMBER\tDATE\tAMOUNT\tPAID\tBALANCE\n";
		//print header
		
		
		for (int i=1;i<=noOfpayments;i++) //loop till all the payments have paid off
		{
			
			if (tempDate[0]==12) // cheking whether the date is on december
			//so that year must be incremented and month must be reset
			{
				tempDate[0] = 12-11;
				tempDate[1] = 1;
				tempDate[2] = tempDate[2]+1;
			}
			else{
				//if not just increment the month
				tempDate[0] = tempDate[0]+1;
				tempDate[1] = 1;
				}
			
		
		
		if (outstBal < monthlyPay)
		//check whether outstanding balance is less than monthly pay
		{
			//calculate new amount to be paid
			double remain = treatmentFee - totalPaid;
			totalPaid = totalPaid+remain;
			outstBal = outstBal-remain;
			
			cout <<i <<"\t" <<tempDate[0] <<"/"<< tempDate[1]<< "/"<< tempDate[2] << "\t" << remain <<"\t" << totalPaid <<"\t"<< outstBal <<endl;	
			
		}
		else
		{
			//calculation when outstanding balance is more than monthly pay
			totalPaid = totalPaid+monthlyPay;
			outstBal = outstBal-monthlyPay;
			cout <<i <<"\t" << tempDate[0] << "/"<<tempDate[1] << "/" << tempDate[2] << "\t"<< monthlyPay << "\t" << setprecision(2) <<fixed << totalPaid <<"\t" << outstBal << endl;	
		}	
			
				
		}
		 		cout << "press any key to exit";
		 		char ch;
		 		cin >> ch;
}
 
	
	
		
		
Program ALLOWS less than 4 digits.

Because you don't check if accNo is less than 4 digits.

 
  while (accNo < 1000 || accNo>9999);


Also I have an ERROR id returned 1 exit status

You need a return 0; after line 124.

Last edited on
Thank you for your response I appreciate your attention and time.
I have added return 0 on to line 125 several times and actually cannot believe it still returns an error messase id returned 1 exit status. Any idea what I could be missing?
Take a look:
Look at the two message lines at the bottom of your screenshot.

The message states you're getting a "permission denied" error trying to open an output file. This is what is causing the -1 return and is unrelated to not having a return 0 at the end of the program (although that is still recommended).

I could not have deduced that from the code you posted, since there is no output file in the code you posted.
Last edited on
Topic archived. No new replies allowed.