Here is my code. the problem is that it only lets you input for the first cout statement then lists the rest of the cout statements without allowing input then ends. idk what going wrong and why the compiler is doing this.
#include <iostream>
using namespace std;
//Write a program that computes the cost of a long-distance call. The cost of
//the call is determined according to the following rate schedule:
//a. Any call started between 8:00 A.M. and 6:00 P.M., Monday through
//Friday, is billed at a rate of $0.40 per minute.
//b. Any call starting before 8:00 A.M. or after 6:00 P.M., Monday through
//Friday, is charged at a rate of $0.25 per minute.
//c. Any call started on a Saturday or Sunday is charged at a rate of $0.15
//per minute.
//The input will consist of the day of the week, the time the call started,
//and the length of the call in minutes. The output will be the cost of the
//call. The time is to be input in 24-hour notation, so the time 1:30 P.M. is
//input as
//13:30
//The day of the week will be read as one of the following pairs of character
//values, which are stored in two variables of type char:
//Mo Tu We Th Fr Sa Su
//Be sure to allow the user to use either uppercase or lowercase letters or a
//combination of the two. The number of minutes will be input as a value
//of type int. (You can assume that the user rounds the input to a whole
//number of minutes.) Your program should include a loop that lets the
//user repeat this calculation until the user says she or he is done.
char choice;
float rate_1=0.45, rate_2=0.25, rate_3=0.15;
int main (int argc, char* argv[])
{
do{
cout<<"This program will compute the total cost of a long distance call \n";
cout<<"To determine the cost please provide for us the following information...\n";
cout<<"Mo Tu We Th Fr Sa Su\n";
char day;
int mtime, time, min;
cout<<endl;
cout<<"Please enter what day you will be making your call then press enter:";
cin>>day;
cout<<endl;
cout<<"Please enter the time the call started in 'Military time'\n";
cout<<"Enter the hours then press enter:";
cin>>mtime;
cout<<endl;
cout<<"Enter the minutes:\n";
cin>>min;
cout<<endl;
cout<<"Please enter the length of the time in minutes <numbers only> of the call then press enter: ";
cin>>time;
cout<<endl;
if ((day=='MO')||(day=='Mo')||(day=='mo')||(day=='TU')||(day=='Tu')||(day=='tu')||(day=='we')||(day=='We')||(day=='WE')||(day=='TH')||(day=='Th')||(day=='th')||(day=='fr')||(day=='Fr')||(day=='FR'))
{
if (((mtime>=8)&&(mtime<=18))&&((min>=0)&&(min<60)))
{
float you_owe;
you_owe=time*rate_1; //$0.40 per minute
cout<<"You will be charged"<<"$"<<you_owe<<" "<<"for the call. \n";
}
else
{
float youre_owe;
youre_owe=time*rate_2; //$0.25 per minute
cout<<"You will be charged"<<"$"<<youre_owe<<" "<<"for the call. \n";
}
}
if ((day=='Su')||(day=='SU')||(day=='su')||(day=='sa')||(day=='SA')||(day=='Sa'))
{
float u_be_owing;
u_be_owing=time*rate_3; //$0.15 per minute
cout<<"You will be charged"<<"$"<<u_be_owing<<" "<<"for the call. \n";
Question
repos
Here is my code. the problem is that it only lets you input for the first cout statement then lists the rest of the cout statements without allowing input then ends. idk what going wrong and why the compiler is doing this.
#include <iostream>
using namespace std;
//Write a program that computes the cost of a long-distance call. The cost of
//the call is determined according to the following rate schedule:
//a. Any call started between 8:00 A.M. and 6:00 P.M., Monday through
//Friday, is billed at a rate of $0.40 per minute.
//b. Any call starting before 8:00 A.M. or after 6:00 P.M., Monday through
//Friday, is charged at a rate of $0.25 per minute.
//c. Any call started on a Saturday or Sunday is charged at a rate of $0.15
//per minute.
//The input will consist of the day of the week, the time the call started,
//and the length of the call in minutes. The output will be the cost of the
//call. The time is to be input in 24-hour notation, so the time 1:30 P.M. is
//input as
//13:30
//The day of the week will be read as one of the following pairs of character
//values, which are stored in two variables of type char:
//Mo Tu We Th Fr Sa Su
//Be sure to allow the user to use either uppercase or lowercase letters or a
//combination of the two. The number of minutes will be input as a value
//of type int. (You can assume that the user rounds the input to a whole
//number of minutes.) Your program should include a loop that lets the
//user repeat this calculation until the user says she or he is done.
char choice;
float rate_1=0.45, rate_2=0.25, rate_3=0.15;
int main (int argc, char* argv[])
{
do{
cout<<"This program will compute the total cost of a long distance call \n";
cout<<"To determine the cost please provide for us the following information...\n";
cout<<"Mo Tu We Th Fr Sa Su\n";
char day;
int mtime, time, min;
cout<<endl;
cout<<"Please enter what day you will be making your call then press enter:";
cin>>day;
cout<<endl;
cout<<"Please enter the time the call started in 'Military time'\n";
cout<<"Enter the hours then press enter:";
cin>>mtime;
cout<<endl;
cout<<"Enter the minutes:\n";
cin>>min;
cout<<endl;
cout<<"Please enter the length of the time in minutes <numbers only> of the call then press enter: ";
cin>>time;
cout<<endl;
if ((day=='MO')||(day=='Mo')||(day=='mo')||(day=='TU')||(day=='Tu')||(day=='tu')||(day=='we')||(day=='We')||(day=='WE')||(day=='TH')||(day=='Th')||(day=='th')||(day=='fr')||(day=='Fr')||(day=='FR'))
{
if (((mtime>=8)&&(mtime<=18))&&((min>=0)&&(min<60)))
{
float you_owe;
you_owe=time*rate_1; //$0.40 per minute
cout<<"You will be charged"<<"$"<<you_owe<<" "<<"for the call. \n";
}
else
{
float youre_owe;
youre_owe=time*rate_2; //$0.25 per minute
cout<<"You will be charged"<<"$"<<youre_owe<<" "<<"for the call. \n";
}
}
if ((day=='Su')||(day=='SU')||(day=='su')||(day=='sa')||(day=='SA')||(day=='Sa'))
{
float u_be_owing;
u_be_owing=time*rate_3; //$0.15 per minute
cout<<"You will be charged"<<"$"<<u_be_owing<<" "<<"for the call. \n";
}
cout <<endl;
cout << "Do another computation? (y/n)" << endl;
cin >> choice;
}while(choice == 'Y' || choice == 'y');
Link to comment
Share on other sites
9 answers to this question
Recommended Posts