wrong output by using argc and argv argumnets

Hello friends

I have written a program to calculate delay between nodes using link.
Code:
//sim.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include<stdlib.h> 
#include <iostream>
#include <fstream>
#include <math.h>
#include <cstdio>

 int main(int argc, char* argv[]) {
 float delay = 0, d_i = atof(argv[0]);
 int i, num_nodes = atoi(argv[1]);
 for(i = 1; i < num_nodes; i++)
 delay += d_i;
 printf("Overall Packet Delay is %2.1f seconds\n",
delay);
 }
then I compiled it as follows
g++ -o sim sim.cc

when i run $./sim 2 5
it gives packet delay is 0.0

where is the error?

please reply
print out argv[0] and argv[1] (or read the documentation on the main function such as http://en.cppreference.com/w/cpp/language/main_function ) and you'll see what the problem is.
Last edited on
Topic archived. No new replies allowed.