Code Crashing. What's the output?

I have this for a HW assignment and I'm supposed to give the entire output of the code but it crashes when I run it, so I can't even see the errors. Help appreciated!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>

double x = 974.23;
namespace one {
double x = 56.1102;
}	
namespace two {
double x = 73.8924;
}

using std::cout;		using std::cin;
void atEnd1(void) {cout << "Bye, bye!\n";}
void atEnd2(void) {cout << "Bye, bye, bye!\n";}

int main(int argc, char *argv[]) {
atexit(atEnd1);	atexit(atEnd2);
double x = 11.001;	short unsigned int i = 0;

cout << "This program ran with " << argc << " input arguments.\n ";
cout << "Do you know " << argv[2] << "?\n";
printf("Here is the second argument:  %7.2f.\n",atof(argv[1]));
//cout << "What will argv[1]+2 be? --> " << argv[1]+2 << "\n";

cout << one::x << " " << two::x << " " << ::x << " " << x << "\n";

std::vector<double> myVals(8,1.618);
for(i=0; i<myVals.size(); i++)
myVals[i] += i+1;
std::vector<double>::iterator vIt = myVals.begin();
double weirdMax = *(std::max_element(myVals.begin(),myVals.end()));
weirdMax += x;
cout << "weirdMax = " << weirdMax << ".\n";
cout << "The size and capacity of myVals are, respectively: ";
cout << myVals.size() << " and " << myVals.capacity() << ".\n";

vIt += 2; printf("The value is %6.1f\n", *(vIt+1));
return 1;
}
The program expects that you pass 2 command-line arguments to the program (3 if you count the program name).
I just re-read the instructions and it said that it should be done on linux.. So I would need to do that to pass the commands?
No you can pass command-line arguments in Windows too, from the command prompt, or if you run your program from an IDE you can probably set the arguments to pass to the program in the IDE somewhere.
The arguments I'm supposed to do are:

37.1
and
BozotheClown

How would I go about doing this? Thanks.
Open up the command prompt (cmd.exe) and navigate to the directory where the exe file is located using the cd command. To run the program with the arguments you write the name of the exe file followed by the arguments separated by space and press enter.
Do I need to make an exe file of the code? I'm using visual studio 2012 desktop. I looked up this: http://www.cplusplus.com/forum/beginner/9192/ but I don't think it worked.

Is an Application file the same as an exe on windows 7?
I guess so. By exe file I mean an executable file, having an .exe file extension on windows.

You can probably specify the arguments from visual studio that will be used when you run the program from visual studio.
Last edited on
Topic archived. No new replies allowed.