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.
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.
#include <iostream>
#include <stdio.h>
int main()
{
constint pack_bread = 6;
constint 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
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.