0

This is the code. When I run it, nothing appears, just darkness. Blank. I'm a beginner, and I don't really know too much about coding. Any help would be appreciated.

#include <iostream>
using namespace std;

int main()

float x;
float y;
float Wynik;
x = 1.4;
y = 5.8;
Wynik = (x * y + x + y) / (x-y);
return 0;

}

bolov
  • 72,283
  • 15
  • 145
  • 224
  • Hi you need to print it to consle. `std::cout << Wynik < – S.R Dec 11 '20 at 09:40
  • 3
    For beginners, start with getting [a good book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) for learning. It should get you step by step from a Hello World program through all basic concepts. – Yksisarvinen Dec 11 '20 at 09:43
  • @S.R -- unless there's a good reason for it (which is not the case here), lines should be terminated with `'\n'`. You don't need the extra stuff that `std::endl` does. – Pete Becker Dec 11 '20 at 14:28
  • This doesn't address the question, but get in the habit of creating variables where they are first used, and initializing them at that point. So: `float x = 1.4; float y = 5.8; float Wynik = (x * y + x + y) / (x - y);`. – Pete Becker Dec 11 '20 at 14:30

3 Answers3

4

Because you aren't printing out anything in your console. To print your results, use std::cout << Wynik;. And also, you have an error in your main function, it's supposed to be like this:

int main() {
    // Your code goes here
}

Also, using namespace std; is considered bad practice since it can lead to conflicts with your other libraries, but you'll read that in a book.

dh4ze
  • 449
  • 1
  • 5
  • 10
3
#include <iostream>
using namespace std;

int main() {

    float x;
    float y;
    float Wynik;
    x = 1.4;
    y = 5.8;
    Wynik = (x * y + x + y) / (x-y);
    cout << Wynik << endl; // This will print your output
    return 0;
}
1
    #include <iostream>

    int main()
    {
      const float x = 1.4;
      const float y = 5.8;
      std::cout << (x * y + x + y) / (x - y) << std::endl; // This will print your output
      return 0;
    }