-2
Warum funktioniert dieser Code nicht wie erwartet?Meine Variable erhält nicht wie erwartet valye
Wenn ich proizvod Start Debugging ist immer auf 1, Fledermaus sollte es
0.75 = 1 - (1/4) and so on.
Mein Code ist dies
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain()
{
int plusminus = 1, brojac = 0;
double proizvod = 1;
double pi;
while (brojac < 6)
{
plusminus = plusminus + 2;
if (brojac % 2 == 0)
{
proizvod = proizvod - (1/plusminus);
}
else
{
proizvod = proizvod + (1/plusminus);
}
pi = proizvod * 4;
brojac++;
}
cout << "Broj PI sa 6 decimala je " << pi << " ." << endl;
}
Sie ganze Zahlen sind geteilt wird. Sie werden nicht automatisch in "double" konvertiert. ('1/3 == 0') – UnholySheep
Formatieren Sie Ihren Code mit etwas Sinn. –