Need help with these random numbers

So I've been trying to learn c++ alone with help of guides, but I came to a problem where I needed to know (as funny as it sounds) how many pack of breads and sausages will I need to make "completos" or hot dogs , but it just gives me back these random numbers.
The proportions are:
1 pack of bread comes with 6
1 pack of sausages comes with 5
1 'completo' uses 1 bread and 1 sausage
Thanks for your time and hope I can get my answer.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <stdio.h>
int main(void)

{
	int panes;
	int vienesa;
	int completos;

	printf("Cuantos completos quieres hacer:\n");
	scanf("%d", &completos);
	
	if(&completos > 0)
	{
	
	vienesa = completos / 5;
	panes = completos / 6; }else { vienesa = 0;
	panes = 0;}  
	printf("Usted necesitara:\n");
	printf("%d",&vienesa,"paquetes de vienesas.\n"); 
	printf("%d" ,&panes, "paquetes de panes\n");
	printf("%d","para hacer",&completos, "completos");
	
}
Mind you, I am still extremely new to C++.....but if I am understanding what your saying correctly, your program is supposed to tell you how many packs of bread and sausage you'll need to make a certain amount of hot dogs. Right?

Do you have to do it in a specific way, or you can use any methods in C++ to do it?
Just a question : If you know how to write a question in English, why didn't you present your code in English too?

(1) - You used printf the wrong way (when printing the output)
(2) - You compare if(&completos > 0), which (&) gives the address of the variable instead of the actual value stored in the variable. Because the address of one variable is always greater than zero, the (if) condition is always true even you do input (completos = 0) in the first place.

C code example :


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
#include <iostream>
#include <stdio.h>

int main()
{
      const int pack_bread = 6;
      const int pack_sausage = 5;

      // For normal variables - initialize them before using!
      int pack_bread_count = 0;
      int pack_sausage_count = 0;
      int hot_dog_count = 0;

      printf("Enter how many hot dogs you need to make : ");
      scanf("%d", &hot_dog_count); printf("\n");
      if(hot_dog_count < 0)hot_dog_count = 0;

      if(hot_dog_count > 0)
      {
            pack_bread_count = hot_dog_count / pack_bread;
            pack_sausage_count = hot_dog_count / pack_sausage;

            if(pack_bread_count == 0) pack_bread_count = 1;
            if(pack_sausage_count == 0) pack_sausage_count = 1;
      }

      printf("Output : \n");
      printf("   + Total of hot dogs : %d\n", hot_dog_count);
      printf("   + Number of packs of breads required : %d\n", pack_bread_count);
      printf("   + Number of packs of sausages required : %d\n\n", pack_sausage_count);

      system("pause");
      return 0;
}


This is cplusplus forum, so let me present cplusplus-style example as well. For starters, learn this :

(1) using namespace std;
(2) std::cout
(3) std::cin
(4) std::cin.get(); // pauses the screen

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
#include <iostream>
#include <stdio.h>

using namespace std;
int main()
{
      const int pack_bread = 6;
      const int pack_sausage = 5;

      // For normal variables - initialize them before using!
      int pack_bread_count = 0;
      int pack_sausage_count = 0;
      int hot_dog_count = 0;

      cout << "Enter how many hot dogs you need to make : ";
      cin >> hot_dog_count ; cout << endl;
      if(hot_dog_count < 0)hot_dog_count = 0;

      if(hot_dog_count > 0)
      {
            pack_bread_count = hot_dog_count / pack_bread;
            pack_sausage_count = hot_dog_count / pack_sausage;

            if(pack_bread_count == 0) pack_bread_count = 1;
            if(pack_sausage_count == 0) pack_sausage_count = 1;
      }

      cout << "Output : " << endl;
      cout << "   + Total of hot dogs : " << hot_dog_count << endl;
      cout << "   + Number of packs of breads required : " << pack_bread_count << endl;
      cout << "   + Number of packs of sausages required : " << pack_sausage_count << endl << endl;
      
      cout << "Please press any key to exit. . .";
      cin.get();
      return 0;
}
Thanks! I'm really new to this and I'm doing problems in spanish. I didn't have the time to translate it all since I was in a hurry, but thanks anyway.
Topic archived. No new replies allowed.