457,958 Members | 1,491 Online Need help? Post your question and get tips & solutions from a community of 457,958 IT Pros & Developers. It's quick & easy.

# need help with this code (heh im a beginner so should be a simple fix)

 P: n/a Okay im doing my final project for my first computer science class(its my major, so it will be my first of many), but anyway im a beginner so im not to great with C++ yet. Anyway this is the error msg that im getting: "Error executing cl.exe" this is the code that I have, but I know whats causing it, ill just show you the whole thing first though //file: Quadratic #include #include #include void main () { char name ; char runagain; double discriminant; double root1; double root2; double a; double b; double c; cout << "What is your name? " << endl; cin.getline (name,10); cout << "Hello " << name << " we are now ready to begin. Lets compute the roots of your quadratic equation" << endl; while (char runagain = "y") { cout << "A-----> "; cin >> a; cout << "B-----> "; cin >> b; cout << "C-----> "; cin >> c; cout << "The equation is " << a << " * x * x + "<< b << " * x + "<< c << endl; if (a==0 && b==0) { cout << " Linear equation, root at " << - c / b << endl; } else { discriminant = b * b - 4 * a * c; if (discriminant < 0); cout << "imaganary roots" << endl; } if (discriminant == 0) { root1 = - b / 2 * a ; root2 = root1; cout << "Two equal real roots: "; cout << "Root 1 = " << root1 << " and Root 2 " << root2; } else { root1 = ( - b + sqrt (discriminant) / (2 * a ) ); root2 = ( - b - sqrt (discriminant) / (2 * a ) ); cout << "Two distinct real roots: " << endl; cout << "Root 1 = " << root1 << " and Root 2 = " << root2 << endl; } cout << "Would you like to run this program again, please enter y for yes, and n for no" << endl; cin >> runagain; } cout << "Have a good day"; } Okay the program worked, but then I have to put a loop in there and thats when I starting getting the error, so im sure its my loop statement thats causing the problem, ive tinkered around with it and still cant figure out how to fix it. Someone said I needed to add "do" after my while loop line, but then I get the same error plus one that says "syntax error: identifier 'cout'". Hopefully this is an easy fix and someone will be able to help me out, thanks in advance! Jul 29 '05 #1
8 Replies

 P: n/a * Bshealey786: Okay im doing my final project for my first computer science class(its my major, so it will be my first of many), but anyway im a beginner so im not to great with C++ yet. Anyway this is the error msg that im getting: "Error executing cl.exe" this is the code that I have, but I know whats causing it, ill just show you the whole thing first though //file: Quadratic #include is not a standard header, use . #include #include void main () 'main' must have result type 'int'. -- A: Because it messes up the order in which people normally read text. Q: Why is it such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet and in e-mail? Jul 29 '05 #2

 P: n/a lol doing that gave me 26 errors, and I guess we are working with old versions of c++, bc ive been told thats not what you use anymore, but thats how it works on ours at school. Thanks though, it worked before I added in the loop, so the loop has to be causing the error Jul 29 '05 #3

 P: n/a Here is a number of ideas Instead of char name; cin.getline (name,10); use #include std::string name; cin >> name; The line while (char runagain = "y") will not compile and if it could it would loop forever You're assigning a char-array (the double quotes) to a char, it should be while (char runagain = 'y') 'y' has a decimal value of 121, which is a no zero value and would resolve to true, hence the loop will loop forever. Perhaps you wanted to say char runagain = 'y'; while (runagain == 'y') The lines if (a==0 && b==0) { cout << ... << - c / b << ... This asserts a divide by zero condition. the if-statement checks that b are equal to 0 and then you divide by b. Forget about the c++ syntax and just check your arithmetic logic first to avoid faulty logic like the example above. Joe Jul 29 '05 #4

 P: n/a You can use a for loop to initialise a variable then check its value. So for ( char runagain='y', runagain=='y'; ) { // code block in here } Alternatively, as you are always going to run the loop once, you can perform a do..while loop thus: do { // codeblock // obtain runagain here. } while ( runagain == 'y' ); Note: it's a linear equation if and only if a is 0 and b is non-zero. If b is 0 then the regular formula will work, although it can be shortened to x = +/- sqrt( -c/a ) Jul 29 '05 #6

 P: n/a I assume cl.exe is the microsoft compiler so that's a compilation issue. I don't know you but I always find it helpful to carefully read all those compiler error messages and even read detail about that error in the compiler manual. Further, it you encountered an error and want us to help, it would make a lot of sense copy and paste all the compiler messages so we know exactly what's going on. Ben Jul 30 '05 #7

 P: n/a "benben" writes: I assume cl.exe is the microsoft compiler so that's a compilation issue. I don't know you but I always find it helpful to carefully read all those compiler error messages and even read detail about that error in the compiler manual. Further, it you encountered an error and want us to help, it would make a lot of sense copy and paste all the compiler messages so we know exactly what's going on. As near as I can tell his error messages resulted from using a compiler that was frozen in time and unable to predict the future syntax of the language. There is real information in the thread, too, so presumably the OP has his problem fixed by now. Jul 30 '05 #8

 P: n/a "Error executing cl.exe" that isn't an error that cl emits. it's coming from nmake or make or whatever you're using to execute the program. somehow your environment changed after an edit, which led you to believe your code is at fault. Aug 4 '05 #9

### This discussion thread is closed

Replies have been disabled for this discussion. 