C++ code: How I can make it stop repeating the question "how many gigabytes of data used? When entering an invalid input? I also have the same issue when entering an invalid package it repeats the pick package option again. When entering a letter instead of a number it goes crazy and spams the package questions multiple times at once. My professor also said that I need Fixed, showpoint, and setprecision in my code. I provided pictures of the errors that have been happening.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

C++ code: How I can make it stop repeating the question "how many gigabytes of data used? When entering an invalid input? I also have the same issue when entering an invalid package it repeats the pick package option again. When entering a letter instead of a number it goes crazy and spams the package questions multiple times at once. My professor also said that I need Fixed, showpoint, and setprecision in my code. I provided pictures of the errors that have been happening. 

Heres the code:

#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main()
{
//variables and constants
int packageType;
double dataUsed;
double monthlyCharges = 0.0;

// Name of the program
cout << "iMobile Bill Calculator ..." << endl;

// Display the pacakge options for user to pick
while (true)
{
cout << "\nSelect a subscription :" << endl;
cout << "\t\t1. Package A" << endl;
cout << "\t\t2. Package B" << endl;
cout << "\t\t3. Package C" << endl;
cout << "Package: ";
cin >> packageType;

switch (packageType)
{
// Monthtly Charges for Plan A
case 1:
{
// When Gigabytes entered is not valid
while (true)
{
cout << "\nHow many gigabytes of data were used? ";
cin >> dataUsed;
if (dataUsed < 0)
{
cout << "Error ... Invalid gigabytes entered. Try again." << endl;
}
else
break;
}
if (dataUsed >= 0 && dataUsed <= 4)
{
monthlyCharges = 39.99;
}
else
// Monthtly Charges for Plan A with additional data costs
{
monthlyCharges = 39.99 + (dataUsed - 4) * 10;
}
// Display the monthly total amount
cout << "The total amount due is $" << monthlyCharges << endl;
break;
}
// Monthtly Charges for Plan B
case 2:
{
// When Gigabytes entered is not valid
while (true)
{
cout << "\nHow many gigabytes of data were used? ";
cin >> dataUsed;
if (dataUsed < 0)
{
cout << "Error ... Invalid gigabytes entered. Try again." << endl;
}
else
break;
}
if (dataUsed >= 0 && dataUsed <= 8)
{
monthlyCharges = 59.99;
}
// Monthtly Charges for Plan B with additional data costs
else
{
monthlyCharges = 59.99 + (dataUsed - 8) * 5;
}
// Display the monthly total amount
cout << "The total amount due is $" << monthlyCharges << endl;
break;
}
// Monthly Charges for Plan C
case 3:
{
monthlyCharges = 75;
cout << "The total amount due is $" << monthlyCharges << endl;
break;
}
// When a package number is not vaild
default:
cout << "Error ... Invalid package. Try again." << endl;
}

if (packageType > 0 && packageType <= 3)
{
break;
}

}

return 0;
}

RecyiMobile Bill Calculator
Select a subscription :
1. Package A
2. Package B
3. Package C
ission His
MicPackage: 0
E Error ... Invalid package. Try again.
Term2022,
Select a subscription :
1. Package A
2. Package B
3. Package C
vel | Pearson
Go
Ch Package: 10
Error .. Invalid package. Try again.
dio Debug Ce
Select a subscription :
1. Package A
2. Package B
3. Package C
ulator
tion pach
e A
e B
e c
Drive
Package:
Transcribed Image Text:RecyiMobile Bill Calculator Select a subscription : 1. Package A 2. Package B 3. Package C ission His MicPackage: 0 E Error ... Invalid package. Try again. Term2022, Select a subscription : 1. Package A 2. Package B 3. Package C vel | Pearson Go Ch Package: 10 Error .. Invalid package. Try again. dio Debug Ce Select a subscription : 1. Package A 2. Package B 3. Package C ulator tion pach e A e B e c Drive Package:
Solution Explorer iMobile Bill Calculator
Select a subscription :
1. Package A
2. Package B
3. Package C
Search Solution Ex
cout << "The total a
break;
Solution 'Mo
}
%3D
A Moblie 4package: 2
// Monthly Charges for P
H Refer
case 3:
ExterrHow many gigabytes of data were used? -100
Head Error ... Invalid gigabytes entered. Try again.
{
monthlyCharges
75;
Resou
cout << "The total a
How many gigabytes of data were used?
Sourc
break;
4.
++ So
// When a package number
default:
cout << "Error
<>
Transcribed Image Text:Solution Explorer iMobile Bill Calculator Select a subscription : 1. Package A 2. Package B 3. Package C Search Solution Ex cout << "The total a break; Solution 'Mo } %3D A Moblie 4package: 2 // Monthly Charges for P H Refer case 3: ExterrHow many gigabytes of data were used? -100 Head Error ... Invalid gigabytes entered. Try again. { monthlyCharges 75; Resou cout << "The total a How many gigabytes of data were used? Sourc break; 4. ++ So // When a package number default: cout << "Error <>
Expert Solution
Step 1c++

I have given errorless code below.

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education