i have a problem calculating the cost with this code. the code is supposed to use the different call rates to calculte but it only uses the first rate. it is supposed to get the total cost of around 4 calls with different rates..sorry if it is too long but it is the smallest segment cuz it has the diiferent conditions for the 3 call rates.

for (i=0;i<S;i++)

{

    if ((time_and_date[i].start.hours<7) && (time_and_date[i].end.hours<=7))
     
       {		
               rate_one =((minutes[i])+(hours[i]*60))*0.10;
       
       }

     if ((time_and_date[i].start.hours<=7)&&(time_and_date[i].end.hours>7)&&(time_and_date[i].end.hours<=16))

       {
	
               temp_value=time_and_date[i].start.hours; 
				
               temp_value2=time_and_date[i].end.hours;

                for(i=8;i<temp_value2;i++)
			
                {

	           count_rate++;

                 }

                 for(i=temp_value;i<7;i++)
			
                 {

	          hour_rate++;

                 }

                 temp_rate=((count_rate*60)+(time_and_date[i].end.minutes))*0.15;

                 rate=(((time_and_date[i].start.minutes))+(hour_rate*60))*0.10;

                 rate_one=(rate+temp_rate);

      }

        if ((time_and_date[i].start.hours>7)&&(time_and_date[i].start.hours<=16) && (time_and_date[i].end.hours<=16))

       {

	  rate_two =((minutes[i])+(hours[i]*60))*0.15;
        
        }

       if((time_and_date[i].start.hours<=16)&&(time_and_date[i].end.hours>16)&&(time_and_date[i].end.hours<23))
	
       {

            temp_value=time_and_date[i].start.hours;
			
            temp_value2=time_and_date[i].end.hours;

            for(i=16;i<temp_value2;i++)

            {

	       count_rate++;

             }

            for(i=temp_value;i<16;i++)
            {

                    hour_rate++;

             }

            temp_rate=((count_rate*60)+(time_and_date[i].end.minutes))*0.12;
            rate=(((time_and_date[i].start.minutes))+(hour_rate*60))*0.15;
            rate_two=(rate+temp_rate);

      }

      if ((time_and_date[i].start.hours>16)&&(time_and_date[i].start.hours<=23) &&(time_and_date[i].end.hours<=23))

       {

             rate_three =((minutes[i])+(hours[i]*60))*0.12;

       }

       if((time_and_date[i].start.hours<=23)&&(time_and_date[i].end.hours>23)&&(time_and_date[i].end.hours<7))
	
        {

              temp_value=time_and_date[i].start.hours;
              temp_value2=time_and_date[i].end.hours;

                 for(i=23;i<temp_value2;i++)

	       {
                  
                  count_rate++;
                 
                }

	  for(i=temp_value;i<23;i++)

	       {

	       hour_rate++;

                }

	temp_rate=((count_rate*60)+(time_and_date[i].end.minutes))*0.10;

	rate=(((time_and_date[i].start.minutes))+(hour_rate*60))*0.15;

	rate_three=(rate+temp_rate);

        }

   }
      rate=rate_one+rate_two+rate_three;

    return rate;	

}

Without knowing the values of the variables its quite impossible to determine the solution to your problem. What compiler and os are you using? You need to learn how to use your compiler's debugger so that you can single-step through the program execution and see that the variable's values are.

am using visual c++ but i posted an attachment of the whole code earlier and i was told it was too much so i just put this segment..how do i use the debugger

Quite simple -- first make sure you compile your program for DEBUG. Then use the functions in the Debug menu. You will use Start Debugging (F5), Step Into (F11) and Step Over (F12) the most. You can save some time by setting breakpoints so that the debugger will stop on the line you set.

It make take a bit to learn the debugger but after that find problems in the code becomes fairly easy.

the code compiles with no error..it gives me a wrong final call rate..i will try the debugging thingy

hey could you also help and check out on another post i put up...its called programing help..havnt got a solution yet

FORMATTING please.... SPACES and NEWLINES are your friend so the code can be read:

if ((time_and_date[i].start.hours <= 7 )  &&
        (time_and_date[i].end.hours   >  7)  &&
        (time_and_date[i].end.hours   <=16))
    {
        temp_rate = ((count_rate*60) + (time_and_date[i].end.minutes)) * 0.12;
        rate = (((time_and_date[i].start.minutes)) + (hour_rate*60)) * 0.15;
        rate_two = (rate + temp_rate);
    }
    if ((time_and_date[i].start.hours >  16)  &&
        (time_and_date[i].start.hours <= 23)  &&
        (time_and_date[i].end.hours   <= 23))

i used the debugging thingy n i kind of got where the poblem is but it isnt solved. the code is supposed to calculate rates for multiple calls but it only uses the last one..for example if there are two phone calls that require the same rate, it calculates the first, then second but it uses the second one..how do i get it to add up both rates??

While you're single-stepping the code, you should also be running through your head your impression of what needs to happen to the data (or following through on paper what you designed to happen).

When what is actually happening is different from what you thought should happen, stop running the code and look closely at the code you wrote and the last thing it did. Somewhere in there is the bug you seek.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.