Decision statments

call charging program using logical, arithmetic operators and decision statements if, if else, nested if, nested if else,:
if
call start from 8:00am - 19:59pm
call charges = 5rs

if
call start from 20:00pm - 07:59am
call charges = 3rs

what will be the call charges if call start from 19:45 and end at 20:15
???????

need code
Last edited on
need code


You need to write code, not us.
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
#include<iostream.h>
main()
{
 	  int startingHour, startingMint, callDuration,totalCharges, totalMint;
 	  
 	  cout<< "enter Starting hour	";
 	  cin>> startingHour;
 	  cout<<"\n";
 	  
 	  cout<< " enter starting minute	";
 	  cin>> startingMint;
 	  cout<<"\n";
 	  
 	  cout<< " enter call duration		";
 	  cin>> callDuration;
 	  cout<<"\n";
 	  
 	  if( startingHour >= 8 && startingHour <=19)
 	  {
	   	  totalMint = startingMint + callDuration;
		  
		  if ( totalMint>= 60)
		  {
		   	   startingHour + 1;
		   	   }
		   	   if( startingHour >= 20)
		   	   {
			   	   totalCharges = (59 - startingMint)*5 +(totalMint - 59)*3; 
  	   				}
 			   else 
				{
				 	totalCharges =   callDuration * 5;
			 		} 
 	  		}
 	  else
 	  {
	   	  
	   	   if( startingHour >= 20 && startingHour <=7)
 	  	   {
		   	   
	   	  	   totalMint = startingMint + callDuration;
		  
 		  	   if ( totalMint>= 60)
 			   {
			   	  	
   	   		 		startingHour + 1;
		   	   		 }
	   	  		   	 if( startingHour >= 20)
		   	   		 {
	  	 			  	 totalCharges = (59 - startingMint)*3 +(totalMint - 59)*5; 
  	   					 }
			 		 else 
						 {
						  	  totalCharges =   callDuration * 3;
							  } 
		  }	
		  	}

 	   	   	cout<< " total charges = " <<totalCharges;


}



this is the code but the else portion is not working it showing output 0

enter starting hour = 1
enter starting minute = 4
enter call duration = 2

total charges = 0



kindly highlight the ERROR
if( startingHour >= 20 && startingHour <=7)

Can you think of any value of startingHour which is bigger than 20 AND less than 7? I can't.

Which bit of code do you think is supposed to be run when you enter 1 as the starting hour? You have not written any code for that.


1
2
#include<iostream.h>
main()
This has not been C++ since before 1998. You should get a new, correct C++ compiler for free instead of whatever 20 year old mess you're using.

Last edited on
if( startingHour >= 20 && startingHour <=7)

i am using the 24 hour format and condition is

if
call start from 20:00pm - 07:59am
call charges = 3rs

and i found 1 mistake after correcting it still not working

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
#include<iostream.h>
main()
{
 	  int startingHour, startingMint, callDuration,totalCharges, totalMint;
 	  
 	  cout<< "enter Starting hour	";
 	  cin>> startingHour;
 	  cout<<"\n";
 	  
 	  cout<< " enter starting minute	";
 	  cin>> startingMint;
 	  cout<<"\n";
 	  
 	  cout<< " enter call duration		";
 	  cin>> callDuration;
 	  cout<<"\n";
 	  
 	  if( startingHour >= 8 && startingHour <=19)
 	  {
	   	  totalMint = startingMint + callDuration;
		  
		  if ( totalMint>= 60)
		  {
		   	   startingHour + 1;
		   	   }
		   	   if( startingHour >= 20)
		   	   {
			   	   totalCharges = (59 - startingMint)*5 +(totalMint - 59)*3; 
  	   				}
 			   else 
				{
				 	totalCharges =   callDuration * 5;
			 		} 
 	  		}
 	  else
 	  {
	   	  
	   	   if( startingHour >= 20 && startingHour <=7)
 	  	   {
		   	   
	   	  	   totalMint = startingMint + callDuration;
		  
 		  	   if ( totalMint>= 60)
 			   {
			   	  	
   	   		 		startingHour + 1;
		   	   		 }
	   	  		   	 if( startingHour >= 21)
		   	   		 {
	  	 			  	 totalCharges = (59 - startingMint)*3 +(totalMint - 59)*5; 
  	   					 }
			 		 else 
						 {
						  	  totalCharges =   callDuration * 3;
							  } 
		  }	
		  	}

 	   	   	cout<< " total charges = " <<totalCharges;


}
if( startingHour >= 20 && startingHour <=7)


24 hour clocks have nothing to do with this.

Tell me a value for startingHour that you think will make this if block run, and I'll explain why it's wrong. This if block will never run. Never ever ever.
suppose startingHour =1
which compiler i should use. my instructor is gave me this. i am using bloodshed DEV-C++
suppose startingHour =1


Okay. So, is this true?
startingHour >= 20 No, startingHour is NOT 20 or more.

Is this true?
startingHour <=7 Yes, startingHour is 7 or less.

So are they BOTH true? No.
So is this true?
startingHour >= 20 && startingHour <=7 No, because this will only be true when they are BOTH true.

Pick another number that you think will make startingHour >= 20 && startingHour <=7 true and I will explain why it does not.
Last edited on
is 1 greater than 20?


damn, Moschops'ed...
Last edited on
Moschops i got it. can i use OR operator instead of AND??????
Can you?????? We're not here to do your homework for you.
Last edited on
if( startingHour <= 20 && startingHour >=7) i think this is the true statment. but its also not working
Last edited on
m not saying to do my home work i am asking for suggestion. well thanks dude :-)
if :

if( startingHour >= 8 && startingHour <=19)

give you one charge, what descision has been made about the other charge?

(hint : i'll charge you this, else i'll charge you that)
Moooce

other charges are applying in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
if( startingHour >= 8 && startingHour <=19)
 	  {
	   	  totalMint = startingMint + callDuration;
		  
		  if ( totalMint>= 60)
		  {
		   	   startingHour + 1;
		   	   }
		   	   if( startingHour >= 20)
		   	   {
			   	   totalCharges = (59 - startingMint)*5 +(totalMint - 59)*3; 
  	   				}
 			   else 
				{
				 	totalCharges =   callDuration * 5;
			 		} 
 	  		}



but the code for these charges is not working
f
call start from 20:00pm - 07:59am
call charges = 3rs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
else
 	  {
	   	  
	   	   if( startingHour >= 20 || startingHour <=7)
 	  	   {
		   	   
	   	  	   totalMint = startingMint + callDuration;
		  
 		  	   if ( totalMint>= 60)
 			   {
			   	  	
   	   		 		startingHour + 1;
		   	   		 }
	   	  		   	 if( startingHour >= 8)
		   	   		 {
	  	 			  	 totalCharges = (59 - startingMint)*3 +(totalMint - 59)*5; 
  	   					 }
			 		 else 
						 {
						  	  totalCharges =   callDuration * 3;
							  } 
		  }	
		  	}



i am unable to find what will be the right statment in if( startingHour >= 20 || startingHour <=7)
Last edited on
Topic archived. No new replies allowed.