0

i have a bit of code consisting of an equation that should substract a specific value in an multidimensional string array off of a double-variable and immediately write it back in the double-variable. It's for a uni-project and i tried searching for a solution here which led me strtod() but it doesn't seem to work.

double einwurf;

User can only enter a positive value over 10 for einwurf (this section works)

array

char *getraenkeListe[3][2]={"Wasser", "1.20", "Cola", "1.50", "Kaffe", "1.50"};

the equation is

einwurf=einwurf-strtod(getraenkeListe[getraenkeWahl-1][1], rueckgabewert=-1);

getraenkeWahl can only be 1, 2 or 3

so getraenkeListe[getraenkeWahl-1][1] should give back 1.20 or 1.50

In the example it stated NULL instead of rueckgabewert=-1, but i thought it's just the value it returns when it fails and if something fails in this project we should return a value of -1 so i swapped it out

is it just not possible to reassigne a variable within the strtod()-function? how do i get it in rueckgabewert without writing a new line so the error-value of strtod() won't get lost?

thanks

Loufi
  • 1,215
  • 1
  • 8
  • 23
  • 1
    This mixture of German and English lets hurt my eyes. It's just like what I hear in Radio ads (before I switch it off). ;-) – Scheff's Cat Dec 05 '18 at 11:07
  • 1
    I'm not sure but if `strtod()` does not accept `1.50` then it might be a localization issue. To become sure about this you could try `1,50`. To improve your question, it would be nice if you could expose a [mcve]. – Scheff's Cat Dec 05 '18 at 11:09
  • `strtod(getraenkeListe[getraenkeWahl-1][1], rueckgabewert=-1)` looks strange somehow. Please, have a look at [`strtod()`](https://en.cppreference.com/w/cpp/string/byte/strtof). The 2nd parameter is `char**` which is dedicated to get an address of a `char*` to store the pointer to text position where parsing ended. No idea how `rueckgabewert=-1` could fit into this. ([Undefined Behavior](https://stackoverflow.com/a/4105123/1505939)?) (You may pass `nullptr` if you don't want to use it.) – Scheff's Cat Dec 05 '18 at 11:16
  • The error value of `strtod()` does not get lost. If the returned pointer in 2nd argument is just the begin of your text, it means, `strtod()` couldn't read anything. (In this case, the returned value of `strtod()` is 0.0 but more or less useless.) – Scheff's Cat Dec 05 '18 at 11:19
  • Sorry for the `nullptr`. In C, it should be `NULL`, of course. (I forgot about the language tag.) – Scheff's Cat Dec 05 '18 at 11:26

0 Answers0