|
|
if(service='R'||'r')
should be if(service == 'R'|| service == 'r')
cout<<"The cost of "<<dayMin<<" minutes is $"<<premiumBill<<"."<<endl;
|
|
booradley60 wrote: |
---|
Your conditions inside your 'if' statements don't convey what you think they do. if(service='R'||'r') should be if(service == 'R'|| service == 'r') This applies to all your conditions. Note the distinction between the '=' and '==' operators. Also remember that you can't chain together logical comparisons like you did; you must specify both sides of the comparison every time. Next, your functions expect parameters. When you call these functions currently, you do so like this: cout<<"The cost of "<<dayMin<<" minutes is $"<<premiumBill<<"."<<endl; However, the call should look more like this: cout << "The cost of " << dayMin << " minutes is $" << premiumBill(dayMin, nightMin) << "." << endl; Notice that the call to premiumBill now has parameters being passed to it. You'll have to figure out logically if it makes sense to pass both dayMin and nightMin every time you invoke the premium function, but the way it is declared now you must pass it two parameters. |
output wrote: |
---|
----jGRASP exec: G:\Computer Programming\C++\a.exe Do you want the regular service or the premium service? r Enter the amount of minutes you need. 45 The cost of 45 minutes is $1. ----jGRASP: operation complete. ----jGRASP exec: G:\Computer Programming\C++\a.exe Do you want the regular service or the premium service? p Enter the amount of minutes you need. 60 The cost of 60 minutes is $1. ----jGRASP: operation complete. |
mynicks wrote: |
---|
line 38 is making me sceptical. Look at this : (min>50) that is a logic operation not arithmetic same counts for line 43. I get the feeling that it is misplaced. I played a little bit with your code. I tested the regular option (r). I get only two possible results: when minutes are <= 50 it always outputs $10 when minutes are >=50.1 it always outputs $10.2 ( before i run your code i did correct some obvious mistakes as TheUnholy says above) |
booradley60 wrote: |
---|
I have a paper about it, but it just has the code that the teacher gave the students. It says to refer to 2 problems in different chapters of the textbook. I would go into the book to find the problems, but we do not have textbooks at home for our programming class. |
booradley60 wrote: |
---|
I was trying to guess what your assignment may be. It seems like if you select the regular option you would pay a $10 base rate, and then 20 cents for every minute beyond 50. I figured the premium plan offered different rates and made the distinction between day and night minutes. |
|
|
|
|
booradley60 wrote: | ||||
---|---|---|---|---|
Ok, so for the regular option, you invoke the regularBill function. In main:
The regularBill function (Notice I've changed the parameter to an int. I don't think you are worried about fractions of a minute, so an int will be fine.):
Then, for premium bills, I don't think the user should decide between day or night. They should be asked for both no matter what. |
|
|
|
|
|
|
if(service=='R'||'r')
and this if(service=='R'|| service == 'r')
This applies to your 'else if' case as well.if(service=='R'||'r')
The OR operator [||], returns true if either of its arguments are true. In this case, the arguments are:if(service=='R'||'r')
is the same as if(false || true)
. We know from how the || operator works that this evaluates to if(true)
, which means we're going to execute the code inside of the if block.
booradley60 wrote: |
---|
Be careful, you corrected one part of your 'if' but not the other. Note the difference between this if(service=='R'||'r') and this if(service=='R'|| service == 'r') This applies to your 'else if' case as well.What's happening here? if(service=='R'||'r') The OR operator [||], returns true if either of its arguments are true. In this case, the arguments are:1. service == 'R' 2. 'r' Let's say we entered 'p' for service. What happens? 1. service == 'R' is FALSE. service is 'p', not 'R'. 2. 'r' is TRUE! Why? 'r' is a character point with some non-zero ASCII code. Any number when coerced to a true/false value becomes true. The only exception is the number 0. The number 0 when interpreted as a true/false value yields false. So, given the evaluation of those conditions, if(service=='R'||'r') is the same as if(false || true) . We know from how the || operator works that this evaluates to if(true) , which means we're going to execute the code inside of the if block. |