User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 396,989 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,916 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 359 | Replies: 14
Reply
Join Date: Jul 2008
Posts: 44
Reputation: gispe is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
gispe gispe is offline Offline
Light Poster

using an if inside a for loop

  #1  
Jul 23rd, 2008
hi ppl!
im here again with another problem, which, is more a question about if what im doing is ok.

the thing is i have to do a problem that counts the total of letters sent, the total of packages sent, total of letters and packages sent on the next day priority, on the next day normal, and the total if its sent over 2 days.
also i have to calculate a big total of letters and packages sent (i mean letters + packages in each day) and the percentage of the total of things sent on the next day priority, of the next day normal, and over 2 days.

i already have a code made, my question if its ok to put a for loop in the middle of a chain of ifs:

//A GENERAL FOR LOOP WOULD BE HERE
if ((peso < 30) && (dia = 7))                    
       cout << " Se le cobraran 8$ " << "\n";                // these 3 are letters, 
else if ((peso < 30) && (dia = 8))               
      cout << " Se le cobraran 5$ " << "\n";
else if ((peso < 30) && (dia = 9))
       cout << " No esta disponible$ " << "\n";
//ANOTHER PUT A FOR LOOP HERE
              else if ((peso > 30) && (peso < 1000) && (dia = 7))         // from here to the end, are packages
                     cout << " Se le cobraran 25$ " << "\n";
              else if ((peso > 30) && (peso < 1000) && (dia = 8))
                     cout << " Se le cobraran 20$ " << "\n";
              else if ((peso > 30) && (peso < 1000) && (dia = 9))
                     cout << " Se le cobraran 15$ " << "\n";
      //AND ANOTHER ONE HERE
                            else if((peso > 1000) && (dia = 7))
                            {
                                   cout << " Se le cobraran 25$ " << "\n";
                                   cout << " Y 2$ adicionales por cada 500 gr de màs" << "\n";
                                   diferencia = ((peso-1000) / 500);
                                   total_a_pagar = (25 + ((diferencia *2) + 2));
                                   cout << " Se le cobraran" << total_a_pagar << " $ en total" << "\n";
                            }
                            else if ((dia = 8) && (peso > 1000))
                            {
                                   cout << " Se le cobraran 20$ " << "\n";
                                   cout << " Y 1.5$ adicionales por cada 500 gr de màs" << "\n";
                                   diferencia = ((peso-1000) / 500);
                                   total_a_pagar = (25 + ((diferencia *2)+2));
                                   cout << " Se le cobraran" << total_a_pagar << " $ en total" << "\n";
                            }
                            else if ((dia = 9)&& (peso > 1000))
                            {
                                   cout << " Se le cobraran 15$ " << "\n";
                                   cout << " Y 1$ adicionales por cada 500 gr de màs" << "\n";
                                   diferencia = ((peso-1000) / 500);
                                   total_a_pagar = (25 + ((diferencia *2)+2));
                                   cout << " Se le cobraran" << total_a_pagar << " $ en total" << "\n";
                            } 

what i want to do is this: the program must consider the hours in which the people work, so the first for loop would control that [for (hour = hour_begining; (hour > hour_begining) && (hour < hour_final); hour++) ]. now, when it comes to the other two for loops, i dont know if they will stop in any way the ifs, or do i have to write the code differently.

in the code:
peso = weight
dia = day
total_a_pagar = is what i have to pay if i send just one (its calculated only for the packages, if its a letter doesnt matter the weight, its a fixed price)



thanks for the help!!
gispe!!

ps: if anything isnt clear, ask me! and if whole code were necessary ill paste it!!
Last edited by Tekmaven : Jul 24th, 2008 at 2:05 am. Reason: Code tags
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2005
Posts: 3,337
Reputation: Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of 
Rep Power: 20
Solved Threads: 376
Colleague
Salem's Avatar
Salem Salem is offline Offline
void main'ers are DOOMed

Re: using an if inside a for loop

  #2  
Jul 23rd, 2008
If we asked for more code, would you still post it without [code][/code] tags?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
Reply With Quote  
Join Date: Jul 2008
Posts: 44
Reputation: gispe is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
gispe gispe is offline Offline
Light Poster

Re: using an if inside a for loop

  #3  
Jul 23rd, 2008
here is the code



// caja_paquete_2.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>


int main(int argc, char* argv[])
{
	using namespace std;

	char tipo_servicio, dia;

	float peso, total_a_pagar = 0, diferencia;      // CALCULA PRECIO UNITARIO DE CADA COSA
	int total_paquete = 0, total_carta = 0;  // TOTALES POR TIPO ENTREGA, incializadas
	int total_dia_sig_prioritario = 0, total_dia_sig_normal = 0, total_2_dias_o_mas = 0; // TOTALES POR DIA, ya inicializadas
	int totales_de_entregas = 0;          // PARA QUE CALCULE EL TOTAL DE ENTREGAS, ya inicializadas
	float porcentaje_dia_sig_prioritario, porcentaje_dia_siguiente_normal, porcentaje_dos_dias_o_mas;     // PORCENTAJES
	float dinero_recaudado = 0;         // TOTAL DINERO RECAUDADO, ya inicializada
	float hora, hora_fin, hora_inicio;         // HORA DEL DIA PARA CARGAR LAS COSAS



	cout << "Ingrese hora a la que empieza a trabajar (hh.mm): ";
	cin >> hora_inicio;
	cout << "\n";

	cout << " Ingrese la hora a la que termina de trabajar (hh.mm): ";
	cin >> hora_fin;
	cout << "\n";

	for (hora = hora_inicio; hora < hora_fin; hora++)
	{
		cout << " Ingrese tipo de servicio:" << "\n";         ////////
		cout << " 1 - Carta" << "\n";                         ////////
		cout << " 2 - Paquete" << "\n";                       //
		cin >> tipo_servicio;                                 //   
			                                                  //
		cout << " Ingrese tipo de entrega: " << "\n";         //          primer ingreso
		cout << " 7 - Dia siguiente prioritario" << "\n";     //              de datos
		cout << " 8 - Dia siguiente normal" << "\n";          //
		cout << " 9 - Dos dias o mas" << "\n";                //
		cin >> dia;                                           //
			                                                  //
		cout << " Ingrese peso EN GRAMOS a enviar: ";         ////////
		cin >> peso;                                          ////////
		cout << "\n";
  

	if ((peso < 30) && (dia = 7))                    //
		cout << " Se le cobraran 8$ " << "\n";       //
	else if ((peso < 30) && (dia = 8))               //
		cout << " Se le cobraran 5$ " << "\n";
	else if ((peso < 30) && (dia = 9))
		cout << " No esta disponible$ " << "\n";
		else if ((peso > 30) && (peso < 1000) && (dia = 7))
			cout << " Se le cobraran 25$ " << "\n";
		else if ((peso > 30) && (peso < 1000) && (dia = 8))
			cout << " Se le cobraran 20$ " << "\n";
		else if ((peso > 30) && (peso < 1000) && (dia = 9))
			cout << " Se le cobraran 15$ " << "\n";
			else if((peso > 1000) && (dia = 7))
			{
				cout << " Se le cobraran 25$ " << "\n";
				cout << " Y 2$ adicionales por cada 500 gr de màs" << "\n";
				diferencia = ((peso-1000) / 500);
				total_a_pagar = (25 + ((diferencia *2) + 2));
				cout << " Se le cobraran" << total_a_pagar << " $ en total" << "\n";
			}
			else if ((dia = 8) && (peso > 1000))
			{
				cout << " Se le cobraran 20$ " << "\n";
				cout << " Y 1.5$ adicionales por cada 500 gr de màs" << "\n";
				diferencia = ((peso-1000) / 500);
				total_a_pagar = (25 + ((diferencia *2)+2));
				cout << " Se le cobraran" << total_a_pagar << " $ en total" << "\n";
			}
			else if ((dia = 9)&& (peso > 1000))
			{
				cout << " Se le cobraran 15$ " << "\n";
				cout << " Y 1$ adicionales por cada 500 gr de màs" << "\n";
				diferencia = ((peso-1000) / 500);
				total_a_pagar = (25 + ((diferencia *2)+2));
				cout << " Se le cobraran" << total_a_pagar << " $ en total" << "\n";
			} 
	}

 system ("PAUSE");


	return 0;
}
Last edited by Tekmaven : Jul 24th, 2008 at 2:07 am. Reason: Code tags
Reply With Quote  
Join Date: Jan 2008
Location: USA East Cost
Posts: 386
Reputation: CoolGamer48 is on a distinguished road 
Rep Power: 1
Solved Threads: 37
CoolGamer48's Avatar
CoolGamer48 CoolGamer48 is offline Offline
Posting Whiz

Re: using an if inside a for loop

  #4  
Jul 23rd, 2008
Salem meant you should wrap your code in code tags (the # button on the top, or just type [ code] YOUR CODE HERE [/code], w/o the spaces between '[' and "code").

Do you want the for loop to be part of this conditional:
else if ((peso > 30) && (peso < 1000) && (dia = 9))
cout << " Se le cobraran 15$ " << "\n";
//for loop only executed if peso is between 30 and 1000 and dia is 9

If so, just wrap the code in curly brackets:
else if ((peso > 30) && (peso < 1000) && (dia = 9))
{
    cout << " Se le cobraran 15$ " << "\n";
    for(;;)
    //your loop here
}
//next else if condition

If you meant that the loop is executed regardless of the above conditional, you can also do that, though the else if after it would need to become a regular if:
/*else*/if((peso > 1000) && (dia = 7))
Last edited by CoolGamer48 : Jul 23rd, 2008 at 5:39 pm.
I'm a student. If my statements seem too absolute, feel free to coat them with "In my opinion..." or "I believe...".
Reply With Quote  
Join Date: Jul 2008
Posts: 44
Reputation: gispe is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
gispe gispe is offline Offline
Light Poster

Re: using an if inside a for loop

  #5  
Jul 23rd, 2008
so, u mean that i should put the for inside the if, n wont modify the ifs instructions?

cuz i have to count the letters sent every day, and then sum it up
Reply With Quote  
Join Date: Jun 2008
Location: Ireland
Posts: 17
Reputation: Epic Tissue is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Epic Tissue's Avatar
Epic Tissue Epic Tissue is offline Offline
Newbie Poster

Re: using an if inside a for loop

  #6  
Jul 23rd, 2008
> my question if its ok to put a for loop in the middle of a chain of ifs

Yes it's ok. Try put it in and see what happens. If it messes up it's the logic that's wrong.
Reply With Quote  
Join Date: Jun 2008
Location: WA, USA
Posts: 645
Reputation: Alex Edwards has a spectacular aura about Alex Edwards has a spectacular aura about 
Rep Power: 3
Solved Threads: 53
Alex Edwards Alex Edwards is offline Offline
Practically a Master Poster

Re: using an if inside a for loop

  #7  
Jul 23rd, 2008
Here's the code in code-tags.

  1. // caja_paquete_2.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6.  
  7.  
  8. int main(int argc, char* argv[])
  9. {
  10. using namespace std;
  11.  
  12. char tipo_servicio, dia;
  13.  
  14. float peso, total_a_pagar = 0, diferencia; // CALCULA PRECIO UNITARIO DE CADA COSA
  15. int total_paquete = 0, total_carta = 0; // TOTALES POR TIPO ENTREGA, incializadas
  16. int total_dia_sig_prioritario = 0, total_dia_sig_normal = 0, total_2_dias_o_mas = 0; // TOTALES POR DIA, ya inicializadas
  17. int totales_de_entregas = 0; // PARA QUE CALCULE EL TOTAL DE ENTREGAS, ya inicializadas
  18. float porcentaje_dia_sig_prioritario, porcentaje_dia_siguiente_normal, porcentaje_dos_dias_o_mas; // PORCENTAJES
  19. float dinero_recaudado = 0; // TOTAL DINERO RECAUDADO, ya inicializada
  20. float hora, hora_fin, hora_inicio; // HORA DEL DIA PARA CARGAR LAS COSAS
  21.  
  22. cout << "Ingrese hora a la que empieza a trabajar (hh.mm): ";
  23. cin >> hora_inicio;
  24. cout << "\n";
  25.  
  26. cout << " Ingrese la hora a la que termina de trabajar (hh.mm): ";
  27. cin >> hora_fin;
  28. cout << "\n";
  29.  
  30. for (hora = hora_inicio; hora < hora_fin; hora++)
  31. {
  32. cout << " Ingrese tipo de servicio:" << "\n"; ////////
  33. cout << " 1 - Carta" << "\n"; ////////
  34. cout << " 2 - Paquete" << "\n"; //
  35. cin >> tipo_servicio; //
  36. //
  37. cout << " Ingrese tipo de entrega: " << "\n"; // primer ingreso
  38. cout << " 7 - Dia siguiente prioritario" << "\n"; // de datos
  39. cout << " 8 - Dia siguiente normal" << "\n"; //
  40. cout << " 9 - Dos dias o mas" << "\n"; //
  41. cin >> dia; //
  42. //
  43. cout << " Ingrese peso EN GRAMOS a enviar: "; ////////
  44. cin >> peso; ////////
  45. cout << "\n";
  46.  
  47. if ((peso < 30) && (dia = 7)) //
  48. cout << " Se le cobraran 8$ " << "\n"; //
  49. else if ((peso < 30) && (dia = 8)) //
  50. cout << " Se le cobraran 5$ " << "\n";
  51. else if ((peso < 30) && (dia = 9))
  52. cout << " No esta disponible$ " << "\n";
  53. else if ((peso > 30) && (peso < 1000) && (dia = 7))
  54. cout << " Se le cobraran 25$ " << "\n";
  55. else if ((peso > 30) && (peso < 1000) && (dia = 8))
  56. cout << " Se le cobraran 20$ " << "\n";
  57. else if ((peso > 30) && (peso < 1000) && (dia = 9))
  58. cout << " Se le cobraran 15$ " << "\n";
  59. else if((peso > 1000) && (dia = 7))
  60. {
  61. cout << " Se le cobraran 25$ " << "\n";
  62. cout << " Y 2$ adicionales por cada 500 gr de màs" << "\n";
  63. diferencia = ((peso-1000) / 500);
  64. total_a_pagar = (25 + ((diferencia *2) + 2));
  65. cout << " Se le cobraran" << total_a_pagar << " $ en total" << "\n";
  66. }
  67. else if ((dia = 8) && (peso > 1000))
  68. {
  69. cout << " Se le cobraran 20$ " << "\n";
  70. cout << " Y 1.5$ adicionales por cada 500 gr de màs" << "\n";
  71. diferencia = ((peso-1000) / 500);
  72. total_a_pagar = (25 + ((diferencia *2)+2));
  73. cout << " Se le cobraran" << total_a_pagar << " $ en total" << "\n";
  74. }
  75. else if ((dia = 9)&& (peso > 1000))
  76. {
  77. cout << " Se le cobraran 15$ " << "\n";
  78. cout << " Y 1$ adicionales por cada 500 gr de màs" << "\n";
  79. diferencia = ((peso-1000) / 500);
  80. total_a_pagar = (25 + ((diferencia *2)+2));
  81. cout << " Se le cobraran" << total_a_pagar << " $ en total" << "\n";
  82. }
  83. }
  84.  
  85. system ("PAUSE");
  86.  
  87.  
  88. return 0;
  89. }

Sorry for "bumping" this thread, but it really gave me a headache to see the code like this and I'm sure it's giving other people a headache too.

Use code tags please! People will be more inclined to help when you do.
Last edited by Alex Edwards : Jul 23rd, 2008 at 7:07 pm.
Reply With Quote  
Join Date: Jan 2008
Posts: 1,449
Reputation: VernonDozier is a jewel in the rough VernonDozier is a jewel in the rough VernonDozier is a jewel in the rough VernonDozier is a jewel in the rough 
Rep Power: 6
Solved Threads: 185
VernonDozier VernonDozier is offline Offline
Nearly a Posting Virtuoso

Re: using an if inside a for loop

  #8  
Jul 23rd, 2008
Originally Posted by gispe View Post
so, u mean that i should put the for inside the if, n wont modify the ifs instructions?

cuz i have to count the letters sent every day, and then sum it up



Please don't use leet-speak. He's asking whether the for-loop should always be executed, regardless of whether the if-condition is true. If it should always be executed, then don't put the for-loop inside the if-statement. If the for-loop should only be executed if the the if-condition is true, then put the for-loop inside the if-statement's brackets.

I don't understand what you mean by this sentence, the red part in particular.

so, u mean that i should put the for inside the if, n wont modify the ifs instructions?

Do you mean "execute" rather than "modify"? The machine code instructions can't be modified when you run the program.
Reply With Quote  
Join Date: Jul 2008
Posts: 44
Reputation: gispe is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
gispe gispe is offline Offline
Light Poster

Re: using an if inside a for loop

  #9  
Jul 23rd, 2008
well, im back here: same program.
i made some modifications n now runs, but the thing is that it puts on screen same message indefinitely.

it reads the hours it worked, what i want to send (package or letter), and the day i want to send it. n then it returns the cost (indefinitely).

there is the code attached, if u want to try it


#
  1.  
  2. // cartas_paquetes_v3.cpp : Defines the entry point for the console application.
  3. //
  4.  
  5. #include "stdafx.h"
  6. #include <iostream>
  7.  
  8.  
  9. int _tmain(int argc, _TCHAR* argv[])
  10. {
  11. using namespace std;
  12.  
  13. char dia, tipo_servicio, horario_trabajo;
  14.  
  15. float peso, total_a_pagar = 0, diferencia; // CALCULA PRECIO UNITARIO DE CADA COSA
  16.  
  17. int total_paquete = 0, total_carta = 0; // TOTALES POR TIPO ENTREGA, incializadas
  18.  
  19. int total_dia_sig_prioritario = 0, total_dia_sig_normal = 0, total_2_dias_o_mas = 0; // TOTALES POR DIA, ya inicializadas
  20. int total_dia_siguiente_prioritario_p = 0, total_dia_siguiente_prioritario_c = 0; // TOTALES SIG. PRIO C Y P , inicializadas
  21. int total_dia_siguiente_prioritario_p1 = 0, total_dia_siguiente_normal_p1 = 0, total_dos_dias_o_mas_p1 = 0; // para paquetes mayores a 1000, inicializadas
  22. int total_dia_siguiente_normal_p = 0, total_dia_siguiente_normal_c = 0; // TOTAL DIA SIG NORMAL, inicializadas
  23. int total_dos_dias_o_mas_p = 0; // TOTAL DOS DIAS O MAS, inicializadas
  24.  
  25. int totales_de_entregas = 0; // PARA QUE CALCULE EL TOTAL DE ENTREGAS, ya inicializadas
  26.  
  27. float porcentaje_dia_sig_prioritario, porcentaje_dia_siguiente_normal, porcentaje_dos_dias_o_mas; // PORCENTAJES
  28. float dinero_recaudado = 0; // TOTAL DINERO RECAUDADO, ya inicializada
  29. float hora = 0, hora_fin, hora_inicio; // HORA DEL DIA PARA CARGAR LAS COSAS
  30.  
  31. int tp, tc; // CONTADORES tp, para paquete tc, para carta
  32.  
  33. cout << "Ingrese hora a la que empieza a trabajar (hh.mm): ";
  34. cin >> hora_inicio; cout << "\n";
  35. cout << " Ingrese la hora a la que termina de trabajar (hh.mm): ";
  36. cin >> hora_fin; cout << "\n";
  37.  
  38. for (hora = hora_inicio; hora < hora_fin; hora++)
  39. {
  40. cout << " Ingrese tipo de servicio:" << "\n";
  41. cout << " 1 - Carta" << "\n";
  42. cout << " 2 - Paquete" << "\n";
  43. cin >> tipo_servicio;
  44. cout << " Ingrese tipo de entrega: " << "\n";
  45. cout << " 7 - Dia siguiente prioritario" << "\n";
  46. cout << " 8 - Dia siguiente normal" << "\n";
  47. cout << " 9 - Dos dias o mas" << "\n";
  48. cin >> dia;
  49. cout << " Ingrese peso EN GRAMOS a enviar: ";
  50. cin >> peso;
  51. cout << "\n";
  52.  
  53. for (tc = 1; tipo_servicio = 1; tc++)
  54. {
  55. if (dia = 7)
  56. {
  57. cout << " Se le cobraran 8$ " << "\n";
  58. total_dia_siguiente_prioritario_c += 1;
  59. }
  60. else if (dia = 8)
  61. {
  62. cout << " Se le cobraran 5$ " << "\n";
  63. total_dia_siguiente_normal_c += 1;
  64. }
  65. else if (dia = 9)
  66. cout << " No esta disponible$ " << "\n";
  67. }
  68. for (tp = 1; tipo_servicio = 2; tp++)
  69. {
  70. if ((peso > 30) && (peso < 1000) && (dia = 7))
  71. {
  72. cout << " Se le cobraran 25$ " << "\n";
  73. total_dia_siguiente_prioritario_p += 1;
  74. }
  75. else if ((peso > 30) && (peso < 1000) && (dia = 8))
  76. {
  77. cout << " Se le cobraran 20$ " << "\n";
  78. total_dia_siguiente_normal_p += 1;
  79. }
  80. else if ((peso > 30) && (peso < 1000) && (dia = 9))
  81. {
  82. cout << " Se le cobraran 15$ " << "\n";
  83. total_dos_dias_o_mas_p += 1;
  84. }
  85. else if((peso > 1000) && (dia = 7))
  86. {
  87. cout << " Se le cobraran 25$ " << "\n";
  88. cout << " Y 2$ adicionales por cada 500 gr de màs" << "\n";
  89. diferencia = ((peso-1000) / 500);
  90. total_a_pagar = (25 + ((diferencia *2) + 2));
  91. cout << " Se le cobraran" << total_a_pagar << " $ en total" << "\n";
  92. total_dia_siguiente_prioritario_p1 += 1;
  93. }
  94. else if ((dia = 8) && (peso > 1000))
  95. {
  96. cout << " Se le cobraran 20$ " << "\n";
  97. cout << " Y 1.5$ adicionales por cada 500 gr de màs" << "\n";
  98. diferencia = ((peso-1000) / 500);
  99. total_a_pagar = (25 + ((diferencia *2)+2));
  100. cout << " Se le cobraran" << total_a_pagar << " $ en total" << "\n";
  101. total_dia_siguiente_normal_p1 += 1;
  102. }
  103. else if ((dia = 9)&& (peso > 1000))
  104. {
  105. cout << " Se le cobraran 15$ " << "\n";
  106. cout << " Y 1$ adicionales por cada 500 gr de màs" << "\n";
  107. diferencia = ((peso-1000) / 500);
  108. total_a_pagar = (25 + ((diferencia *2)+2));
  109. cout << " Se le cobraran" << total_a_pagar << " $ en total" << "\n";
  110. total_dos_dias_o_mas_p1 += 1;
  111. }
  112. }
  113. }
  114.  
  115.  
  116. total_paquete = total_dia_siguiente_normal_p + total_dos_dias_o_mas_p + total_dia_siguiente_prioritario_p; // TOTAL PAQUETE
  117. total_carta = total_dia_siguiente_prioritario_c + total_dia_siguiente_normal_c; //TOTAL CARTAS
  118.  
  119. total_dia_sig_prioritario = total_dia_siguiente_prioritario_p + total_dia_siguiente_prioritario_c; //TOTAL DIA SIGUIENTE PRIORITARIO
  120. total_dia_sig_normal = total_dia_siguiente_normal_p + total_dia_siguiente_normal_c; // TOTAL DIA SIGUIENTE NORMAL
  121. total_2_dias_o_mas = total_dos_dias_o_mas_p; // TOTAL DOS DIAS O MAS
  122.  
  123. totales_de_entregas = total_paquete + total_carta; //TOTAL DINERO RECAUDADO
  124. // dinero_recaudado = ;
  125.  
  126. system ("PAUSE");
  127. return 0;
  128.  
  129. }
  130.  
Last edited by Tekmaven : Jul 24th, 2008 at 2:08 am. Reason: Code tags
Attached Files
File Type: cpp cartas_paquetes_v3.cpp (5.3 KB, 1 views)
Reply With Quote  
Join Date: Jul 2008
Posts: 44
Reputation: gispe is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
gispe gispe is offline Offline
Light Poster

Re: using an if inside a for loop

  #10  
Jul 23rd, 2008
// cartas_paquetes_v3.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>


int _tmain(int argc, _TCHAR* argv[])
{
using namespace std;

char dia, tipo_servicio, horario_trabajo;

float peso, total_a_pagar = 0, diferencia; // CALCULA PRECIO UNITARIO DE CADA COSA

int total_paquete = 0, total_carta = 0; // TOTALES POR TIPO ENTREGA, incializadas

int total_dia_sig_prioritario = 0, total_dia_sig_normal = 0, total_2_dias_o_mas = 0; // TOTALES POR DIA, ya inicializadas
int total_dia_siguiente_prioritario_p = 0, total_dia_siguiente_prioritario_c = 0; // TOTALES SIG. PRIO C Y P , inicializadas
int total_dia_siguiente_prioritario_p1 = 0, total_dia_siguiente_normal_p1 = 0, total_dos_dias_o_mas_p1 = 0; // para paquetes mayores a 1000, inicializadas
int total_dia_siguiente_normal_p = 0, total_dia_siguiente_normal_c = 0; // TOTAL DIA SIG NORMAL, inicializadas
int total_dos_dias_o_mas_p = 0; // TOTAL DOS DIAS O MAS, inicializadas

int totales_de_entregas = 0; // PARA QUE CALCULE EL TOTAL DE ENTREGAS, ya inicializadas

float porcentaje_dia_sig_prioritario, porcentaje_dia_siguiente_normal, porcentaje_dos_dias_o_mas; // PORCENTAJES
float dinero_recaudado = 0; // TOTAL DINERO RECAUDADO, ya inicializada
float hora = 0, hora_fin, hora_inicio; // HORA DEL DIA PARA CARGAR LAS COSAS

int tp, tc; // CONTADORES tp, para paquete tc, para carta

cout << "Ingrese hora a la que empieza a trabajar (hh.mm): "; 
cin >> hora_inicio; cout << "\n"; 
cout << " Ingrese la hora a la que termina de trabajar (hh.mm): "; 
cin >> hora_fin; cout << "\n"; 

for (hora = hora_inicio; hora < hora_fin; hora++) 
{ 
cout << " Ingrese tipo de servicio:" << "\n"; 
cout << " 1 - Carta" << "\n"; 
cout << " 2 - Paquete" << "\n"; 
cin >> tipo_servicio; 
cout << " Ingrese tipo de entrega: " << "\n"; 
cout << " 7 - Dia siguiente prioritario" << "\n"; 
cout << " 8 - Dia siguiente normal" << "\n"; 
cout << " 9 - Dos dias o mas" << "\n"; 
cin >> dia; 
cout << " Ingrese peso EN GRAMOS a enviar: ";
cin >> peso; 
cout << "\n"; 

for (tc = 1; tipo_servicio = 1; tc++)
{
if (dia = 7) 
{ 
cout << " Se le cobraran 8$ " << "\n";
total_dia_siguiente_prioritario_c += 1;
}
else if (dia = 8)
{
cout << " Se le cobraran 5$ " << "\n";
total_dia_siguiente_normal_c += 1;
}
else if (dia = 9) 
cout << " No esta disponible$ " << "\n"; 
}
for (tp = 1; tipo_servicio = 2; tp++)
{
if ((peso > 30) && (peso < 1000) && (dia = 7)) 
{
cout << " Se le cobraran 25$ " << "\n"; 
total_dia_siguiente_prioritario_p += 1; 
}
else if ((peso > 30) && (peso < 1000) && (dia = 8)) 
{
cout << " Se le cobraran 20$ " << "\n"; 
total_dia_siguiente_normal_p += 1;
}
else if ((peso > 30) && (peso < 1000) && (dia = 9))
{
cout << " Se le cobraran 15$ " << "\n"; 
total_dos_dias_o_mas_p += 1;
}
else if((peso > 1000) && (dia = 7)) 
{ 
cout << " Se le cobraran 25$ " << "\n"; 
cout << " Y 2$ adicionales por cada 500 gr de màs" << "\n"; 
diferencia = ((peso-1000) / 500); 
total_a_pagar = (25 + ((diferencia *2) + 2)); 
cout << " Se le cobraran" << total_a_pagar << " $ en total" << "\n";
total_dia_siguiente_prioritario_p1 += 1;
} 
else if ((dia = 8) && (peso > 1000)) 
{ 
cout << " Se le cobraran 20$ " << "\n"; 
cout << " Y 1.5$ adicionales por cada 500 gr de màs" << "\n"; 
diferencia = ((peso-1000) / 500); 
total_a_pagar = (25 + ((diferencia *2)+2)); 
cout << " Se le cobraran" << total_a_pagar << " $ en total" << "\n"; 
total_dia_siguiente_normal_p1 += 1;
} 
else if ((dia = 9)&& (peso > 1000))
{ 
cout << " Se le cobraran 15$ " << "\n"; 
cout << " Y 1$ adicionales por cada 500 gr de màs" << "\n"; 
diferencia = ((peso-1000) / 500); 
total_a_pagar = (25 + ((diferencia *2)+2)); 
cout << " Se le cobraran" << total_a_pagar << " $ en total" << "\n";
total_dos_dias_o_mas_p1 += 1;
}
}
}


total_paquete = total_dia_siguiente_normal_p + total_dos_dias_o_mas_p + total_dia_siguiente_prioritario_p; // TOTAL PAQUETE
total_carta = total_dia_siguiente_prioritario_c + total_dia_siguiente_normal_c; //TOTAL CARTAS

total_dia_sig_prioritario = total_dia_siguiente_prioritario_p + total_dia_siguiente_prioritario_c; //TOTAL DIA SIGUIENTE PRIORITARIO
total_dia_sig_normal = total_dia_siguiente_normal_p + total_dia_siguiente_normal_c; // TOTAL DIA SIGUIENTE NORMAL
total_2_dias_o_mas = total_dos_dias_o_mas_p; // TOTAL DOS DIAS O MAS

totales_de_entregas = total_paquete + total_carta; //TOTAL DINERO RECAUDADO
// dinero_recaudado = ;

system ("PAUSE");
return 0;

}
Last edited by Tekmaven : Jul 24th, 2008 at 2:09 am. Reason: Code tags
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

&nbs