C++ quesion with compling

Status
Not open for further replies.

aaronkupen

Fully Optimized
Messages
1,848
Location
Pittsburgh, PA
<code>
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

int main(int nNumberofArgs, char* pszArgs[])
{
cout << "Welcome to MyMath calculator.";
cout << "Enter the first digit you would like to calculate with.";
int nFirst;
cin >> nFirst;

cout << "Enter the second digit you would like to calculate with.";
int nSecond;
cin >> nSecond;

int nSum, nDifference, nProduct;
double dQuotient;

nSum = nFirst + nSecond;
nDifference = nFirst - nSecond;
nProduct = nFirst * nSecond;

cout << nSum;
cout << nDifference;
cout << nProduct;

if (nSecond != 0)
{
double dFirst, dSecond;
dFirst = nFirst;
dSecond = nSecond;

dQuotient = dFirst/dSecond;
cout << dQuotient;
}
else
{
cout << "You can not divide by zero";
}
system("PAUSE");
return 0;
}

</code>

That is the code I am putting into dev C++ at my school during java class. When i compile i get a message that says line 2, file H:\c++\2 (my program is H:\C++\MyMath), and it just says unable to run program file. There might be something wrong with my code or the schools security isnt allowing me to use this compiler, because i installed it on my own during my free time. Any help would be appreciated.

P.S. I don't know how to show code on this properly, if you haven't noticed already.
 
The code compiles fine on my computer. Which means it is probably to do with the set up of the compiler. Ensure you have the classpaths (or whatever they are called in C++) set correctly.

What compiler are you using and how are you running it? (e.g. g++ from Linux command line...)

P.S. you were pretty close with the <code>, it is actually square brackets rather than triangle ones though, but good guess!
 
Alright thanks, at school we are using Windows XP Pro, and the program I use is called Dev C++. I don't think i have the privelages in my computer at school to set the classpath, but when i installed it at home i didnt need to worry about that.
 
It is possible that there are restrictions on what can and cannot be run, but since you are creating your own applications it is unlikely otherwise you wouldnt be able to run any of them.

Since the paths you give are H:\... i'm assuming you have your files on a network drive somewhere. If you installed Dev-C++ to the local computer then it is likely the compiler is only looking on the local drive rather than where your files are. If you go to to Options there is a Compiler Options option, choose that and make sure that your paths are correct. There is less chance of you having privelages to run applications from the local machines hard drive than from your network filestore. Alternatively try reinstalling Dev-C++, but to your H drive.
 
Status
Not open for further replies.
Back
Top Bottom