Why does my program not react to any arguments?
Posted
by
Electric Coffee
on Stack Overflow
See other posts from Stack Overflow
or by Electric Coffee
Published on 2013-10-29T09:36:57Z
Indexed on
2013/10/29
9:53 UTC
Read the original article
Hit count: 167
I have a simple test program in C++ that prints out attributes of a circle
#include <iostream>
#include <stdlib.h>
#include "hidden_functions.h" // contains the Circle class
using namespace std;
void print_circle_attributes(float r) {
Circle* c = new Circle(r);
cout << "radius: " << c->get_radius() << endl;
cout << "diameter: " << c->get_diameter() << endl;
cout << "area: " << c->get_area() << endl;
cout << "circumference: " << c->get_circumference() << endl;
cout << endl;
delete c;
}
int main(int argc, const char* argv[]) {
float input = atof(argv[0]);
print_circle_attributes(input);
return 0;
}
when I run my program with the parameter 2.4
it outputs:
radius: 0.0
diameter: 0.0
area: 0.0
circumference: 0.0
I've previously tested the program without the parameter, but simply using static values, and it ran just fine; so I know there's nothing wrong with the class I made...
So what did I do wrong here?
Note: the header is called hidden_functions.h
because it served to test out how it would work if I had functions not declared in the header
© Stack Overflow or respective owner