#declararion

24 messages ยท Page 1 of 1 (latest)

slender flint
#

#include <iostream>

int doubleNumber() {
std::cin >> x;
int x{};

return 2 * x;
}

int main() {
int x{doubleNumber()};
std::cout << x << '\n';
}

robust tideBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

robust tideBOT
#
#include <iostream>

int doubleNumber() {
  std::cin >> x;
  int x{};

  return 2 * x;
}

int main() {
  int x{doubleNumber()};
  std::cout << x << '\n';
}
Oppenheimer
violet quest
slender flint
violet quest
#

what needs to happen for you to use them?

slender flint
# violet quest so think about how variables work

This std::cin>>x; is input then after the input,the input is stored in the variable int x{};
Its logical this way for input to afterwards go in the variable

You can't start with the variable then input doesn't make sense

violet quest
#

the problem is, if x is not defined when you take input from std::cin, where does the input go?

#

think of it this way

#

if there's no basket to collect fruits in, where do i store the fruits?

slender flint
violet quest
#

yes but in our case the fruit really needs a basket

#

it needs to know that there's a basket otherwise it will say "I cannot jump into the dark, I'll die!"

slender flint
violet quest
#

the basket comes into existence once the fruit has already dropped into the abyss, because that's what you decided to do

slender flint
violet quest
slender flint
#

!solved