-1

Is there a way to get a double with the ARGV[] function?

I've tried this, but it did not work in the way i want it to. My "solution" code is:

int MarkGenerator(double argc, double argv[])
{
    if (argc > 3){
        OnError("Too few arguments for mark calculator", -3);
    }
    else{
        double MaxPoint = argv[1];
        double PointsReached = argv[2];
        double temp = 0;


        temp = PointsReached * MaxPoint;
        printf("%d\n", temp);
        temp = temp * 5;
        printf("%d\n", temp);
        temp = temp ++;
        printf("%d\n", temp);
    }
}

The code works, but not in the way i want it to.

any solutions?

SKD
  • 464
  • 1
  • 4
  • 16
Dominic Järmann
  • 361
  • 1
  • 7
  • 18

1 Answers1

2

Here are some suggested changes.

#include<stdio.h>
#include<stdlib.h>

//argc is an int and argv is an array of char *

int MarkGenerator(int argc, char * argv[])  
{

    if (argc < 3){

        OnError("Too few arguments for mark calculator", -3);

    }else{
// The function gets its arguments as strings (char *).
// Take each of the strings and convert it to double
        double MaxPoint = strtod(argv[1], NULL);

        double PointsReached = strtod(argv[2], NULL);

        double temp = 0;   


        temp = PointsReached * MaxPoint;
// Use "%lf" to print a double
        printf("%lf\n", temp);

        temp = temp * 5;

        printf("%lf\n", temp);

        temp = temp ++;

        printf("%lf\n", temp);

    }

}

//argc is an int and argv is an array of char *

// main function's standard signature

int main(int argc, char * argv[])

{

 // Note how arguments are passed
 MarkGenerator(argc, argv);

}
ramana_k
  • 1,933
  • 2
  • 10
  • 14