Hello, I need some assistance with my code. So with this question, I need to combine for loop and if/else statements. However there are problems. 1. (I'm not finished with the code) When I loop the entire code, it gives me a higher number than intended for each customer. 2. For home-phone, it doubles the cout statment meaning it gives vat and total bill twice.
This is the question.
A telecommunication company offers two types of phone services: home phone and mobile
phone.
The home phone has a monthly rental fee of $25.00 per unit and a charge of $0.25 per minute of
airtime.
The mobile phone has two packages: pay-as-you-go and pre-paid.
The pay-as-you-go package is billed at $0.50 per minute of airtime.
The pre-paid package is a fixed monthly cost of $50.00.
Write a program, PhoneService.cpp, to calculate the bill for ten (10) customers. For each
customer, the program should prompt the user for the type of phone service (1: home phone and
2: mobile phone). The user is then asked to enter the number of minutes of airtime used. If the
user has a mobile phone they are prompted to enter which package they subscribe to (3: pay-asyou-go
and 4: pre-paid). VAT is charged at 12.5% for each customer. The program should print
the type of phone service (home phone or mobile phone), package if any (mobile phone only),
the number of minutes used, the cost of the airtime, the VAT charged and the total bill.
The program should also output the total bill and total VAT of the ten (10) customers.
Here is my code.
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
|
#include <iostream>
using namespace std;
int main(){
int home_phone;
int mobile_phone;
int phone_service;
int count;
int package;
int airtime;
int prepaid;
int paygo;//pay as you go
double phonerental_fee;
double phone_charge;
double mobile_charge;
double vat;
double total_bill;
phone_charge=0.25;
vat=0.125;
phonerental_fee=25;
mobile_charge=0.50;
cout<<"Enter the phone service(1 for home phone and 2 for mobile phone): ";
cin>>phone_service;
cout<<"Enter the amount of minutes of airtime used: ";
cin>>airtime;
if(phone_service==1){
phone_charge=(phone_charge*airtime)+phonerental_fee;
vat=vat*phone_charge;
total_bill=vat+phone_charge;
cout<<"Vat charged: $"<<vat<<endl;
cout<<"Bill of the customer: $"<<total_bill<<endl;//Home Phone
}
else{
cout<<"Enter the mobile package(3 for pay-as-you-go or 4 for pre-paid): ";
cin>>package;
}
if(package==3){
mobile_charge=mobile_charge*airtime;
vat=vat*mobile_charge;
total_bill=vat+mobile_charge;
cout<<"Vat charged: $"<<vat<<endl;
cout<<"Bill of the customer: $"<<total_bill;//Mobile Phone Package 3
}
else{
prepaid=50;
vat=vat*prepaid;
total_bill=vat+prepaid;
cout<<"Vat charged: $"<<vat<<endl;
cout<<"Bill of the customer: $"<<total_bill;//Mobile phone package 4
}
}
|