473,789 Members | 2,773 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

n00b help

borland c++ 5.01

character constant must be one or two characters long

get this when compiling my first c++ program can anyone out there help?

it is highlighting this line as the problem

cout << "Please Enter First number: ";

that is correct isnt it though?

here is the code i have used...

#include <iostream.h>
void main (void)
{
int iFirst, iSecond, iAnswer;
char cOperator, cCmd;
cout << endl;
cout << endl;
cout << "Press any key to start the program or type help to view help: ";
cin >> cCmd; endl;
if (cCmd == 'help')
cout << "Help File" endl;
cout << endl;
cout << "Using this calculator is simple below is the key for the
operators"; endl;
cout << "+ = Add \n - = Subtract \n / = Divide \n * = Multiply";
cout << endl;
cout << "Please restart to program to continue"; endl;
else
cout << "Please select which operator would would like to use +/-: ";
cin >> cOperator; endl;
cout << "Please Enter First number: ";
cin >> iFirst; endl;
cout << "Please Enter Second Number: ";
cin >> iSecond;
if (cOperator == '+')
iAnswer = iFirst+iSecond;
else if
(cOperator == '/')
iAnswer = iFirst/iSecond;
else if
(cOperator == '-')
iAnswer = iFirst-iSecond;
else if
(cOperator == '*')
iAnswer = iFirst*iSecond;
else
cout << endl;
cout << "****Please Input A Correct Operator****" endl;
cout << "The Answer To your Sum is: ";
cout << iAnswer;
}
i know it is probably not the easiest way to create a simple calculator but
i know this way will work but i dont know what is casusing the failure when
i try to compile

any help would be much appreciated
--
Thanks,

Chris.
Jul 22 '05
12 2134
Howard wrote:
<rant>

Ever used CodeWarrior? In order to maintain compatibility with OS9, they
sttill give you a void main() function when creating a project. It's not a
matter of someone "telling you" it's right, it's just what you get when
starting a project. Granted, it's non-standard, and ought to be changed
(both by the user and by Metrowerks), but in the context in which it was
used, it's correct, in that it compiles and executes without error


<RANT> Who the hell cares. If you have to bend over to support a non-standard
compiler, that's fine. Howevever, we recommend the standard language
here. Frankly, it's got nothing to do with OS9 but everything to do
with CodeWarriors poor implementation. Whether nor not the OS has a
return value, main still needs to be an int-returning function.

Simmilarly for your other issues. The idea is people come here for
instruction. Telling them to do non-standard things just because some
compilers support it isn't productive.
Jul 22 '05 #11

"John Harrison" <jo************ *@hotmail.com> wrote in message
news:2u******** *****@uni-berlin.de...

"Christo" <ch***@juststuf f.co.uk> wrote in message
news:2u******** *****@uni-berlin.de...

"John Harrison" <jo************ *@hotmail.com> wrote in message
news:2u******** *****@uni-berlin.de...
>
> "Christo" <ch***@juststuf f.co.uk> wrote in message
> news:2u******** *****@uni-berlin.de...
>>
>>
>> we have not covered strings in the intro to c++ course yet at uni,
>> just
> int,
>> float and char, so i havent used them, i dont want to get confused early > on,
>> even though i have programmed before with vb and used php i think c++ is >> going to be a step up for me.
>>
>> I got the program working with one minor problem... whenever i get my
> answer
>> it prints this line regardless if i input the correct operator (+ - * /) >>
>
> It doesn't when I run it. And nor can I see any reason that it would. I
> think you must be mistaken, probably the code you have posted and the code > you are running are not the same.
>
> And please drop all those silly endl
>
> cin >> cCmd; endl;
>
> This endl is doing NOTHING.
>
> And replace all the other endl with \n
>
> cout << "Help File" << endl;
>
> should be
>
> cout << "Help File\n";
>
> john
>
>


ok thank you, i have just been taught that i thought endl; took you onto
a
new line, i am not using a GUI for this just the console, at the minute i

am
a begginner


endl does take you to a new line on output (it does nothing on input) but
so
does '\n'. The difference is that \n is easier to type and that endl as
well
as taking you to a newline also flushes the output stream. Almost all the
time you don't care about flushing the output stream, maybe you don't even
know what it means.

cin >> cCmd; endl;

is just plain wrong, endl has no meaning on input, and if this exercise is
being marked you'll lose marks for that.

cout << "Help File" << endl;

is OK, but it flushes the output stream for no obviously good reason. To
me
it just seems like one of those things that gets copied (or taught) for no
discernable reason but everyone ends up doing it anyway.

But anyway, the main thing is that you got your program working. Did you
sort out why that extra line was always appearing?

john


oh damn i am stupid i didnt realize i had it on the cin

haha

not yet no, i am thining it might just be my machine, stuck it on my account
at uni so i check it out on friday and ask me lecturer about it.

Thanks for the info
Jul 22 '05 #12

"Ron Natalie" <ro*@sensor.com > wrote in message
news:41******** *************** @news.newshosti ng.com...
Howard wrote:
<rant>

Ever used CodeWarrior? In order to maintain compatibility with OS9, they
sttill give you a void main() function when creating a project. It's not
a matter of someone "telling you" it's right, it's just what you get when
starting a project. Granted, it's non-standard, and ought to be changed
(both by the user and by Metrowerks), but in the context in which it was
used, it's correct, in that it compiles and executes without error
<RANT> Who the hell cares. If you have to bend over to support a
non-standard
compiler, that's fine. Howevever, we recommend the standard language
here. Frankly, it's got nothing to do with OS9 but everything to do
with CodeWarriors poor implementation. Whether nor not the OS has a
return value, main still needs to be an int-returning function.


(Just going by CWRon's response when I asked why their main returns void.)

Simmilarly for your other issues. The idea is people come here for
instruction. Telling them to do non-standard things just because some
compilers support it isn't productive.


I'm not advocating telling them to do the wrong thing, just not to
concentrate *so much* on those two items when responding to a post that's
about something else. And to respond in a kindler, gentler manner, not jump
on them for making a mistake that their IDE may actually have made for them.
That's all.

-Howard


Jul 22 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1788
by: Matt | last post by:
I'd like to overwrite just one line of a binary file, based on a position set by seek(). Is there no way to do this? As far as I can tell I need to read the whole file, change the line, and write it all back out. Not exactly easy on the memory, but I see no other solution. so far: patchme.seek(offset) patchme.write(a2b_hex(edit)) # the data is in hex first patchme.close
3
1533
by: Anupam Kapoor | last post by:
hi all, a python n00b, so please bear with me. i have a simple question: i generally name python sources as a-simple-python-example.py. when i try to import a module named as above, i (obviously) get tracebacks from python interpreter. is there a way to continue naming python sources as above, and still use it as python modules ? i can ofcourse change the name to
1
1544
by: newgenre | last post by:
I am using a pre-built package of code for my site, which is called EasyDisc. All it does is it creates an interactive forum on your site, like any forum you see anywhere. I am having a problem getting started as I am new to .NET and sql. The app, once unzipped, tells me to "Make note of your SQL server name, username, password, database name. You need to supply these info. later." My problem is I don't know where to find out that info....
2
1476
by: ducky | last post by:
Hi all, The only programming experience i have under my belt so far is VB. I'm just starting out on C++ and wonder if anybody suggests and good (free) starting points for me to get going. I'm wondering about tutorials, source code, etc... Stuff that will take me from absolute square 1. Also, which compilers would be suggested? i have the bloodshed one and microsoft's visual studio express version as well. Are there any others that...
4
10146
by: onefry | last post by:
Hey I have this prog that i'm working on, starting my first c++ class and kind of a n00b to programming here it is #include <iostream> #include <cstdlib> using namespace std;
6
1506
by: Charles | last post by:
I am learning from the Accelerated C++ book. The following example doesn't work and I don't know why: #include <iostream> #include <string> int main () { const std::string exclam = "!"; const std::string message = "Hello" + ", world" + exclam; return 0; }
8
1423
by: HardHackz | last post by:
Hey, I'm trying to learn C++, the problem is, when I do cout << "Hello World!"; it always opens dos and closes it to quickly to see...i know im a total n00b, but any help?
0
1137
by: hockeyjk | last post by:
All, I'm writing a program that creates a histogram of data. IDLE is freezing up after the window opens (doesn't prompt user or graph anything). The window that opens is named "tk" rather than the name I assign to it. Can anyone shed light on why. EDIT: Nevermind. The error was resulting because I was attempting to run the file from my flash drive. Who knew. n00b. Can an admin delete this thread?
2
4230
by: benwah1983 | last post by:
Greetings, Here is my problem: The following code shows a div with two small nested divs (images with a title), then the div is closed. Another one opens and a "random text" is displayed. <div style="width: 500px;"> <div style="float: left; padding: 20px;"> Image Title 1<br/> <img src="test.jpg"/> </div> <div style="float: left; padding: 20px;">
0
10200
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10142
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9986
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9021
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7529
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6769
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5422
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4093
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3703
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.