-
April 26th, 2012, 08:58 PM
#1
Do While Issues
The following code seems to not work...after the first do while completes it goes on to the second one although the condition isn't met...i tried putting breaks in enclosing it in brackets...i don't know what else to do
Code:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int account_number;
int minutes;
char service;
double amount_due;
double day_min;
double night_min;
double regular;
double premium;
cout << fixed << showpoint;
cout << setprecision(2);
cout<<"Please enter your account number."<< endl;
cin>> account_number;
cout<<"Please enter account type.(R or r for regular service, P or p for premium service.)"<<endl;
cin>>service;
do
{
cout << "Enter the amount of minutes used." << endl;
cin >> minutes;
if (minutes <= 50)
{
amount_due=10.00;
cout << "Amount due:$" << amount_due << endl;
cout << "Account Number:" << account_number << endl;
cout << "Minutes used:" << minutes << "" <<endl;
break;
}
else ( minutes > 50 );
{
amount_due= ((minutes-50 ) * .20 + 10.00);
cout << "Amount due:$" << amount_due << endl;
cout << "Account Number:" << account_number << endl;
cout << "Minutes used:" << minutes << "" <<endl;
break;
}
}
while(service= 'r' || 'R' ) ;
// this is where is goes wrong
do
{
cout<< "How many minutes were used during the day?";
cin >> day_min;
cout<< "How many minutes were used during the night?";
cin >>night_min;
if(day_min <= 75)
{
amount_due=25.00;
cout << "Amount due for day minutes:$" << amount_due << endl;
cout << "Account Number:" << account_number << endl;
cout << " Day minutes used:" << day_min << "" <<endl;
break;
}
else if (day_min > 75)
{
amount_due = ((day_min - 75) *.10)+ 25.00;
cout << "Amount due for day minutes:$" << amount_due << endl;
cout << "Account Number:" << account_number << endl;
cout << " Day minutes used:" << day_min << "" <<endl;
break;
}
else if (night_min <= 100)
{
amount_due=25.00;
cout << "Amount due for night minutes:$" << amount_due << endl;
cout << "Account Number:" << account_number << endl;
cout << " Night minutes used:" << night_min << "" <<endl;
break;
}
else
{
amount_due=amount_due = ((night_min - 100) * .05)+ 25.00;
cout<<"Amount due for night minutes:$"<<amount_due<<endl;
cout << "Account Number:" << account_number << endl;
cout << " Night minutes used:" << night_min << "" <<endl;
break;
}
}
while ( service = 'p' || 'P');
cin.get();
cin.get();
return 0;
}
-
April 26th, 2012, 09:53 PM
#2
Re: Do While Issues
In both the if and else of the first do while loop, you have a break. This breaks out of the do while loop.
-
April 26th, 2012, 09:57 PM
#3
Re: Do While Issues
no for example when the user inputs an r or R it calculates the bill then goes on to the condition as if it was premium service
-
April 26th, 2012, 10:10 PM
#4
Re: Do While Issues
Right...that is what a do while loop. It executes at least once. Then, depending on the condition it may execute again or fall to the next statement. You probably want a do while loop before the calculations. In this loop you get the input from the user and verify it is valid.
-
April 26th, 2012, 10:23 PM
#5
Re: Do While Issues
yea i figured it out thank you
-
April 27th, 2012, 05:44 AM
#6
Re: Do While Issues
while(service= 'r' || 'R' ) ;
That condition is always true for several reasons.
-
April 27th, 2012, 09:04 AM
#7
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|