Please help! I need help figuring out:(

Project 2 is a continuation of Project 1. Convert Project 1 into a menu-controlled program. Add validation for the number of minutes so numbers less than 0 are not accepted. Add functionality to process a data file containing multiple records.


Add a menu to offer the user a choice of creating a single telephone bill with payment processing or creating multiple telephone bills (without payment processing) from a data file. Add an option to quit the program. The menu should be the first thing displayed when your program begins executing. The menu format should match the one in the Sample Output.

Allow the user to continue making menu choices until they choose the option to quit. Always display the menu before prompting the user for a menu option. Properly handle an invalid menu choice. The user should have an unlimited number of chances to enter a valid menu choice.

Validate the user’s input for payment amount to allow user an unlimited number of chances to enter a valid payment amount.

Add functionality to create and display telephone bills by reading input from the TelephoneData.txt text file. When the user selects the option to create multiple telephone bills, bills should be calculated and displayed for every record in the file without the user needing to do anything else. The TelephoneData .txt file contains 5 records, but your program must be able to process an identically formatted file with any number of records without counting the records. You do not need to process payment information if this option is chosen by the user.

Save your .cpp file using the required naming format.

Click the assignment link to upload your file.

Information in the TelephoneData.txt:

Leslie Knope
1456 Plymouth Street
Pawnee
IN
47408
117

Tom Haveford
689 Lil Sebastian Avenue
Eagleton
IN
47320
34

April Ludgate
1123 9th Avenue
Wamapoke
IN
48034
60

Jery Gergich
3124 Woodbridge Road
Pawnee
IN
47407
378

Donna Meagle
1200 Elysian Fields Blvd
Eagleton
IN
47322
245




Sample Output (user response shown in bold)
Welcome to the CPCC Telephone System

1 – Create Single Telephone Bill
2 – Create Multiple Telephone Bills
3 – Quit

Enter your choice: 1



Enter the name of the customer: Larry Smith
Enter street address: 122 Main Street
Enter city: Charlotte
Enter state: NC
Enter zip code: 23499
Enter the number of minutes used: 157



Larry Smith
122 Main Street
Charlotte, NC 23499

Amount Owed: $31.28



Enter the amount received from customer: 5000



Denomination Number
Dollars 18
Quarters 2
Dimes 2
Nickels 0
Pennies 2




1 – Create Single Telephone Bill
2 – Create Multiple Telephone Bills
3 – Quit

Enter your choice: 2


Leslie Knope
1456 Plymouth Street
Pawnee, IN 47408
Amount Owed: $33.19

Tom Haveford
689 Lil Sebastian Avenue
Pawnee, IN 47408
Amount Owed: $28.40

April Ludgate
1123 9th Avenue
Wamapoke, IN 48034
Amount Owed: $29.42

Jery Gergich
3124 Woodbridge Road
Eagleton, IN 47322
Amount Owed: $40.12

Donna Meagle
1200 Elysian Fields Blvd
Eagleton, IN 47322
Amount Owed: $34.80



1 – Create Single Telephone Bill
2 – Create Multiple Telephone Bills
3 – Quit

Enter your choice: 44

44 is not a valid choice



1 – Create Single Telephone Bill
2 – Create Multiple Telephone Bills
3 – Quit

Enter your choice: 3

Thank you. Closing program.


Original program:

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
// This Program is created to generate the phone bill 

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

//Calculate the total cost 

int calcamountOwed(int usedMin)
{
int amount= 0;
int baseCost=25;
if(usedMin<60)
{amount=baseCost+(usedMin*0.10);	}

else if(usedMin>=60 && usedMin<120){
amount = baseCost+(usedMin+0.07);}
else if (usedMin >=120){
amount= baseCost + (usedMin * 0.04);
}
return amount;
}
//Show the amount of change that the customer gets back

void showAmountReturn (int amountRecevied , int amountOwed){
int dollarsReturn = 0;
int quartersReturn = 0;
int dimesReturn = 0;
int nickelsReturn = 0;
int penniesReturn = 0;
int totalChange = amountRecevied - amountOwed;

if (totalChange > 0){

dollarsReturn = (totalChange, 100);
penniesReturn = (totalChange - dollarsReturn) * 100;
quartersReturn = penniesReturn / 25;
penniesReturn = penniesReturn - (quartersReturn*25);
dimesReturn = penniesReturn / 10;
penniesReturn = penniesReturn - (dimesReturn*10);
nickelsReturn = penniesReturn / 5;
penniesReturn = penniesReturn - (nickelsReturn*5); }


cout << "Denomination"<<"Number"<<endl;
cout<<"Dollars"<<dollarsReturn<<endl;
cout<<"Quarters"<<quartersReturn<<endl;
cout<<"Dimes"<<dimesReturn<<endl;
cout<<"Nickels"<<nickelsReturn<<endl;
cout<<"Pennies"<<penniesReturn<<endl;
}
int main() {
string customerName = "" ;
string streetAddress = "";
string city = "";
string state = "";
string zipcode = "";
int usedMin = 0;
double amountReceived = 0;
double amountOwed = 0;
int choice;
//Menu options
cout<<"Welcome to the CPCC Telephone System"<<endl<<endl;
cout<<"1-Create Single Telephone Bill"<<endl;
cout<<"2-Create Multiple Telephone Bills"<<endl;
cout<<"3-Quit"<<endl<<endl;

cout<<"Enter your choice: ";
cin>>choice;



cout<< "Enter name of customer:" ;
cin>> customerName ;
cout<< "Enter street address: ";
cin>> streetAddress;
cout<< "Enter City: ";
cin>> city ;
cout<< "Enter state: ";
cin>> state ;
cout<<"Enter zipcode: ";
cin>> zipcode ;
cout<< "Enter the number of minutes used: ";
cin>> usedMin ;
amountOwed = calcamountOwed(usedMin);
//Display the bill 

cout<< customerName << endl;
cout<< streetAddress<< endl;
cout<< city << state << zipcode << endl;
cout<<"Owed Amount:$ " << amountOwed<< endl;
cout<<"Enter amount recieved from the customer: ";
cin>> amountReceived;
amountReceived = (amountReceived / 100);
if (amountReceived >= amountOwed){
showAmountReturn (amountReceived, amountOwed);

}

else{
cout<< "Amount received is insuffiecient, Therefore the bill can't be completed."<<endl;
}
return 0;

}

Last edited on
You might want to put your code in code format for better clarification.
Hello blackwaterdad,


PLEASE ALWAYS USE CODE TAGS (the <> formatting button), to the right of this box, when posting code.

It makes it easier to read your code and also easier to respond to your post.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.

I found the second link to be the most help.



Right now your program looks like it might work. I will have to dig into it tomorrow.

After two years of working with menus I have found it is better to put the menu in a function surrounded by a do/while loop allowing you to make a choice and validate that choice before returning a valid choice to the calling function. Where I use a switch to process the menu choice.

You might want to consider putting most of what is in "main" in a do/while loop to keep the program continuing until the exit is called for.

I would also consider putting the input in a function and the "Display the bill" section in a function just leaving "main" to control what is done.

Hope that helps,

Andy
Topic archived. No new replies allowed.