Can't find the error... Please help

Write your question here.
well I have to do this small program which takes in a couple of user input like, time of day the user called, day the user called and how long was the call in minutes and output the cost, everything goes well, but it's returning a wrong output, when dealing with the weekend values, tried the debugger and nothing, so last resort is posting here and seeing if some clear minded people can help... have other programs to do, so I can't keep wasting time like this.

the problem is in the first if statement, where if the first letter is not one of the char stated, its suppose to ignore that nest, yet it still allocates the rate of that if statement and out puts the wrong value. I know of easier ways of doing this, but the professor explicitly wants us to nest if statements, would appreciate the help.
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
 
#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
 int counT = 1,MinutesIn = 0;
 double Hours = 0, Minutes = 0, Sum = 0;
 char answer = ' ',FletterDay = ' ',SletterDay = ' ',SemiC = ' ';
 double RateOne = 0;
    do
        {  Sum = 0;
            cout << "\nEnter the hour your call started: \n";
            cin >> Hours >> SemiC >> Minutes;
            cout << "\nEnter the two beginning letters of the day: \n";
            cin >> FletterDay >> SletterDay;
            cout << "\nEnter the minutes the call lasted: \n";
            cin >> MinutesIn;

            FletterDay = toupper(FletterDay);
            SletterDay = toupper(SletterDay);

            if((FletterDay == 'M' || 'T' || 'W' || 'F' )  && (SletterDay == 'O' || 'U' || 'E' || 'H' || 'R'))
                {

                if((Hours >= 8) && (Hours <=18))
                    {
                    if((Hours == 18) && (Minutes > 0))
                        {
                            RateOne = 0.25;
                            Sum = MinutesIn * RateOne;
                            cout << endl<< "This is how much your call will cost: " << '$' <<Sum;}
                    else
                        {
                            RateOne = 0.45;
                            Sum = MinutesIn * RateOne;
                            cout << endl<< "This is how much your call will cost: " << '$' <<Sum;}
                    }
                else if(Hours <= 7 || Hours >= 19 )
                    {
                        RateOne = 0.25;
                        Sum = MinutesIn * RateOne;
                        cout << endl<< "This is how much your call will cost: " << '$' <<Sum;}


                }
            else if((FletterDay == 'S') && (SletterDay == 'U' || 'A'))
                {
                    RateOne = 0.15;
                    Sum = MinutesIn * RateOne;
                    cout << endl<< "This is how much your call will cost: " << '$' <<Sum;
                }


          cout << "\nwould you like to go again?(Y/N): ";
          cin >> answer;
          answer = toupper(answer);
          counT++;
        }while(answer!='N' && answer == 'Y');
    return 0;
}

 
@DrPatrickBateman

if((FletterDay == 'M' || 'T' || 'W' || 'F' ) && (SletterDay == 'O' || 'U' || 'E' || 'H' || 'R'))
should be
if((FletterDay == 'M' || FletterDay 'T' || FletterDay'W' || FletterDay'F' ) && (SletterDay == 'O' ||SletterDay == 'U' ||SletterDay == 'E' ||SletterDay == 'H' || SletterDay =='R'))
Actually guy up there missed few "==", but you got the point.
Thank you whitenite1 and MatthewRock, I've been trying to make up for days i haven't been codding and my mind is slipping. got a deadline for tomorrow and im still about 3 problems to go and i've barely slept, anyways thanks...
Yeah, I copied and pasted but forgot to copy as much as I really needed on the FletterDay section. ( Forgot the ==). Then didn't proofread it afterwards. Thanks for catching it, MatthewRock.
DrPatrickBateman wrote:
tried the debugger and nothing


Really? Are you sure of what the difference between a compiler & a debugger is?

A debugger allows one to step through code 1 line at a time while keeping an eye on the values of variables. A compiler gives warnings & errors about the syntax of the code.

Using a debugger, you would have got to line 25 & seen that it always true, despite the FLetter being 'S' (a weekend), or even if it is 'Z'

Anyway good luck!!
with all due respect and maybe you mean well, but yeah, I know the diff between a debugger and a compiler (and a linker if that makes you feel any better), the only warning coming up was that of a parentheses which really didnt matter (because i fixed it) and after all it did compile, so it was obviously a logical error, which is why I posted the problem, it was answered, I thanked, don't need the condescension TheIdeasMan. Anyway good day...
I did mean well (always do), and wasn't trying to be condescending, I guess tone is a difficult thing to convey on the internet.

From my point of view it is hard to gauge how much people know, all I have is the code they write & the comments they make.

You have said that you have barely slept & have a deadline, so the easiest thing from your point of view is to ask. Sure enough you had an answer in 8 minutes - that's great & and is why we are all here.

I mention advice about debuggers because they are such a powerful & very valuable tools to use in finding logical errors.

Anyway, no hard feelings from my end :+D

Regards
Last edited on
Topic archived. No new replies allowed.