473,414 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

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

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 <iostream.h>
#include <math.h>
#include <string>

void main ()

{

char name [10];
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 1984
* 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 <iostream.h>
<iostream.h> is not a standard header, use <iostream>.

#include <math.h>
#include <string>

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
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
Here is a number of ideas

Instead of
char name[10];
cin.getline (name,10);
use
#include <string>
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
Bshealey786 wrote:
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"
My telepathy bill didn't show up this month. Maybe you could
give some tiny indication of where this error occurs? I see
lots of output statements in your code. Did any of them work?
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 <iostream.h>
As others have said, you want <iostream>. That is, assuming your
compiler supports the standard. That means that the items you
refer to are then in a namespace, so things like cout will require
that you refer to them as std::cout or else read about the "using"
keyword.
#include <math.h>
#include <string>
Since you are using the standard <string> header, not string.h
and not <cstring> you need to be aware that this has pulled in
the stuff relating to the standard library class "string" and
not the C-related stuff about char arrays.

You want: C-related char array stuff - include <string.h> or <cstring>
You want: C++ standard class string - include <string>
void main ()
This should be

int main(void)

or one of the other standard forms.

{

char name [10];
char runagain;
Hmmmm. Ok, runagain is here.
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")
And there's another runagain. And it's not *tested* against 'y'
it's set equal to "y". Hmmm... Does this compile?

You want something like so:

runagain = 'y';
while(runagain =='y')

See, you need to initialize the variable, and you need to test
in the loop, not assign. And you don't want to declare another
variable called runagain.
{

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;
}
In a quadratic eqn ax^2 + bx +c=0, if a and b are both 0, it is not a
linear equation, it's c=0. Or, to smack you from the other direction,
if b is zero, what is -c/b? It's a run-time error is what it is.
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;
}
You never checked for a negative discriminant. If it's negatvie, what
will happen when you take its square root? A run-time error is what.
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,
I'm doubting it.
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!


So, is your question "how do I do while loops?" If so, you need
to read your text and understand the syntax.
Socks

Jul 29 '05 #5
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
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
"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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Jeff Wagner | last post by:
I am in the process of learning Python (obsessively so). I've been through a few tutorials and read a Python book that was lent to me. I am now trying to put what I've learned to use by rewriting...
4
by: Active8 | last post by:
I did this once and can't remember how <blush> so I read the reportlab user guid. It says to unzip the reportlab archive - this is on w2k, BTW, with Python23 - to a directory and make a file...
25
by: Delta | last post by:
Drop Down Menu Mozilla : work well widowed elements such as drop downs, except for flash movies IE : work well so far http://pwp.netcabo.pt/falmartins/index.htm
7
by: Jack Addington | last post by:
I've got a fairly simple application implementation that over time is going to get a lot bigger. I'm really trying to implement it in a way that will facilitate the growth. I am first writing a...
5
by: JackM | last post by:
I need a little guidance putting a script together. I'm trying to read a list of image links from a text file (not a database) and display them in a table on my page. I want to display them in rows...
20
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site...
1
by: H. Fraser | last post by:
I've downloaded all of the code and video dealing with the RSS Reader but when i try to run it, it throws an exception, saying 404 page not found. And, As a total beginner, i've no idea where...
2
by: hellt | last post by:
HI all, i found winreg module from http://www.rutherfurd.net/python/winreg/index.html very useful and simple, instead _winreg. But i have a problem with this module, in its iterable part. look...
10
by: andrew.smith.cpp | last post by:
Hello :-) how can i play a ".wav" file in C++.means with the help of the C++ code i just want to play a "a.wav" file more then 10 times. i just want to play background music. Can i do it in C++ ?...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.