dimanche 2 mai 2021

The output of my code is not correct, what did i do wrong?

I am writing a program that calculates the charges for telephone calls based: the time of the call, the duration of the call, and the selected plan of the user. The program should ask the user to enter the following:

• Selected plan (A or B)

• Start time of the call entered in hours minutes seconds in a 24-hour format. For example, entering 14:23:11 means 2 pm at minute 23, at 11 seconds.

• End time of the call entered in hours minutes seconds.

• Date of the call entered in Name-of-the-day day-of-the-month month. For example, entering Thurs 22 4 means Thursday 22nd April. Days of the week should be {Sat, Sun, Mon, Tues, Wed, Thurs, Fri} Based on the entered information, the program should calculate the duration of the call in minutes, and display:

• The entered call information (Start time, end time, date, and duration of the call in minutes)

• The user’s plan displayed in a tabular format, where all the rates would be displayed in the right alignment.

• The calculated rate of the call. The cost of the call is determined according to the Plans

The output of the Call rate is always equal to zero and in some cases, there is no output.

Here is my code:

int main()

char input;
cout<< "Select your plan: "<< endl;
cout<< " A \n" << " B \n" << endl;
cin>> input;
cout<< "Enter the call start time in hours minutes seconds in a 24-hour format: "<< endl;
int Hrs_start, Mins_start, Secs_start;
cin >> Hrs_start >> Mins_start >> Secs_start;
int Hrs_End, Mins_End, Secs_End;
cout << "Enter the call end time in hours minutes seconds in a 24-hour format:" << endl;
cin>> Hrs_End >> Mins_End >>  Secs_End;
string dayOfweek;
int dayOfTheMonth, Month;
cout<< "Enter Date of the call in this format:" << endl << "Name-of-the-day day-of-the-month month:"<< endl;
cin >> dayOfweek >>  dayOfTheMonth >> Month;
int secs;
if ( Secs_End> Secs_start ) {
    secs= Secs_End-Secs_start;
} else if ( Secs_start> Secs_End ) {
 secs= Secs_start-Secs_End;
 } else { secs=0; }
int mins;
if ( Mins_End>Mins_start) {
    mins= Mins_End-Mins_start;
} else if ( Mins_start> Mins_End) {
mins= Mins_start-Mins_End;
} else {mins=0;}
int hrs;
hrs= Hrs_End-Hrs_start;

float duration;
duration= hrs*60 + mins + secs/60;
float CallRate;
if (input=='a' || input=='A') {
    if ( dayOfweek== "Sun" || "Mon" || "Tues" || "Wed" || "Thurs" ) {
            if ( Hrs_start>7 && Hrs_start<17 ) {
                    if ( duration<15 ) {
                        CallRate= 0.60*duration;}
                        } else { CallRate= 0.80*duration;}
            if ((Hrs_start<7) || (Hrs_start>17 && Mins_start>1))  {
                    CallRate= 0.45*duration;
                    }
             }
    else if (dayOfweek== "Fri" ||  "Sat") {
        CallRate= 0.25 *duration;
        }
    // Displaying
cout<< setw(20)<< "Call Info:"<<endl;
cout<< setw(20)<< "Start Time:" << " " << Hrs_start << ":" << Mins_start << ":" << Secs_start<<endl;
cout<< setw(20)<< "End Time: " << " " << Hrs_End << ":" << Mins_End << ":" << Secs_start<<endl;
cout<< setw(20)<< "Date Of The Call:" << " " << dayOfweek << " " << dayOfTheMonth << ":" << Month<<endl;
cout<< setw(20) << "Plan" << "A" << ":" << endl;
cout<< setw(20) <<"Call Time"<< setw(20) << "Call Day" << setw(20)<< "Duration" << setw(20) << "Rate" << endl;
cout<< setw(20) <<"7:00 am to 5:00 pm" << setw(20) << "Sun-Thurs" << setw(20) << "<15 mins" << setw(20) << "0.6" << endl;
cout<< setw(20) <<"7:00 am to 5:00 pm" << setw(20) << "Sun-Thurs" << setw(20) << ">=15 mins" << setw(20) << "0.8" << endl;
cout<< setw(20) <<"5:01 pm to 6:59 am" << setw(20) << "Sun-Thurs" << setw(20) << "any" << setw(20) << "0.45" << endl;
cout<< setw(20) <<"any" << setw(20) << "Fri-Sat" << setw(20) << "any" << setw(20) << "0.25" << endl;
cout << "Call Rate: "<< " " <<" L.E." <<" "<< CallRate;
    }
else  if (input=='b'|| input=='B') {
    if ( dayOfweek== "Sun" || "Mon" || "Tues" || "Wed" ) {
            if ( Hrs_start>7 && Hrs_start<17 ) {
                    if ( duration<15 ) {
                        CallRate= 0.60*duration;}
                        } else { CallRate= 0.80*duration;}
            if ((Hrs_start<7) || (Hrs_start>17 && Mins_start>1))  {
                    CallRate= 0.45*duration;
                    }
             }
    else if (dayOfweek== "Fri" ||  "Sat" || "Thurs" ) {
        CallRate= 0.25 *duration;
        }
cout<< setw(20)<< "Call Info:"<< setw(20) << endl;
cout<< setw(20)<< "Start Time:" <<  setw(20) << Hrs_start << ":" << Mins_start << ":" << Secs_start<< endl;
cout<< setw(20)<< "End Time: " << setw(20) << Hrs_End << ":" << Mins_End << ":" << Secs_start<<endl;
cout<< setw(20)<< "Date Of The Call:" << setw(20)<< dayOfweek << " " << dayOfTheMonth << ":" << Month<<endl;
cout<< setw(20) << "Plan" << "B" << ":" << endl;
cout<< setw(20) <<"Call Time"<< setw(20) << "Call Day" << setw(20)<< "Duration" << setw(20) << "Rate" << endl;
cout<< setw(20) <<"7:00 am to 5:00 pm" << setw(20) << "Sun-Wed" << setw(20) << "<30 mins" << setw(20) << "0.6" << endl;
cout<< setw(20) <<"7:00 am to 5:00 pm" << setw(20) << "Sun-Wed" << setw(20) << ">=30 mins" << setw(20) << "0.8" << endl;
cout<< setw(20) <<"5:01 pm to 6:59 am" << setw(20) << "Sun-Wed  " << setw(20) << "any" << setw(20) << "0.45" << endl;
cout<< setw(20) <<"any" << setw(20) << "Thurs-Fri-Sat" << setw(20) << "any" << setw(20) << "0.25" << endl;
cout << "Call Rate: "<< " " <<"L.E."<<""<< CallRate;

Aucun commentaire:

Enregistrer un commentaire