if i do this: - #include <iostream>
-
-
int main()
-
-
{
-
char number1 = '9' , number2 = '1' , answer ;
-
answer = '9' + '1'
-
-
cout << answer << endl ;
-
cin.get()
-
}
then the result will be: :
and if i do this : -
#include <iostream>
-
-
int main()
-
-
{
-
char number1 = 9 , number2 = 1 , answer ;
-
answer = 9 + 1
-
-
cout << answer << endl ;
-
cin.get()
-
}
whats the result now?
49 2063
'1' is just another notation for the Latin 1 (formerly known as ASCII) code for the
code point 49. '9' has code point value 57. So basically you're adding 49+57.
kind regards,
Jos
'1' is just another notation for the Latin 1 (formerly known as ASCII) code for the
code point 49. '9' has code point value 57. So basically you're adding 49+57.
kind regards,
Jos
mcfaker, I mean, dorkz, did you try putting it into a compiler?
And please use code tags in the future.
thanks , but you mean that in the first example with the apostrofs, the result will be : 49 + 57 = 106, and 106 is character 'j' ??? do you mean that?
thanks , but you mean that in the first example with the apostrofs, the result will be : 49 + 57 = 106, and 106 is character 'j' ??? do you mean that?
I don't know what the code point value of a lower case 'j' is, but if it is 106, then yes,
that's what I mean.
kind regards,
Jos
yes it is 'j'
but , by the second example , the example without the apostrofs , what is the result of this? 10?
hello? coolpeople coming to help me.
hello? coolpeople coming to help me.
You do know how to do simple additions do you?
kind regards,
Jos
You do know how to do simple additions do you?
kind regards,
Jos
And if you don't want to do addition, see post #3.
yes i know, but come on answer please, cause ur soo smart,please answer that question. thank you , thank you , thank you
look 9 + 1 without apostrofs is 10 anyhow?
please answer wirhout apostrofs, will it be 10??
dorkz-
Please check your PM's - they are in the top right of the page.
Thanks,
sicarie
im in shock! but please answer, then i stop answering?ok?
im in shock! but please answer, then i stop answering?ok?
Everything is answered already. '1'+'9'= 106; 1+9= 10.
kind regards,
Jos
yes, yes fiendly, thank you!
hey, if i start this program
#include < iostream >
int main()
{
int numberone = '1' , numbertwo = '9' , numberthree ;
numberthree = numberone + numbertwo ;
cout << numberthree ;
cin.get() ;
}
can i put these '1' and '9' in integers???
and something else: if i can put it into integers, the result would be 106?
thanks for answering
please ban me again
no i mean dont ban me!!!!
no i mean dont ban me!!!!
I asked you to do something very simple. That was read the Posting Guidelines and follow them.
You did the same things I warned you against: double-posting, not using code tags, etc..., and now you're doing them again.
Read the Posting Guidelines. Follow them and you won't get warned, banned, or spoken harshly to.
Not only that, but Jos answered you, and you could always put it in a compiler and figure it out.
Of course it's 106. That's what your program displays.
Now, what is your question?
ok i read it, but where is it?
dorkz-
Please check your PM's - they are in the top right of the page.
Thanks,
sicarie
Funny how that reading thing helps.
So, since you don't want to use that account: The Posting Guidelines yet again.
but the next quetion is, : but can i set characters in integers?
but the next quetion is, : but can i set characters in integers?
Why don't you take a minute to read the guidelines before blindly posting again?
but the next quetion is, : but can i set characters in integers?
Yes you can; read up on integer promotion and try to figure out what the result
'll be for the following:
Compile it, test it, play with it a bit and please try to understand it. Asking all
sorts of questions without trying to find the answer is not the way to acquire
any knowledge.
kind regards,
Jos
but when i compile this , its coming with errors -
#include "stdafx.h"
-
-
-
int _tmain(int argc, _TCHAR* argv[])
-
{
-
int number1 = '9' , number2 = '1' , answer ;
-
answer = '9' + '1' ;
-
-
cout << answer;
-
cin.get();
-
-
}
-
error: 1>------ Build started: Project: er, Configuration: Debug Win32 ------
1>Compiling...
1>er.cpp
1>c:\documents and settings\eigenaar\mijn documenten\visual studio 2005\projects\er\er\er.cpp(12) : error C2065: 'cout' : undeclared identifier
1>c:\documents and settings\eigenaar\mijn documenten\visual studio 2005\projects\er\er\er.cpp(13) : error C2065: 'cin' : undeclared identifier
1>c:\documents and settings\eigenaar\mijn documenten\visual studio 2005\projects\er\er\er.cpp(13) : error C2228: left of '.get' must have class/struct/union
1> type is ''unknown-type''
1>Build log was saved at "file://c:\Documents and Settings\Eigenaar\Mijn documenten\Visual Studio 2005\Projects\er\er\Debug\BuildLog.htm"
1>er - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
dont understand what to change!
Funny how that reading thing helps.
So, since you don't want to use that account: The Posting Guidelines yet again.
READ THE PART ABOUT CODE TAGS AND HOW THEY WORK.
Comments in code -
#include "stdafx.h"
-
// you need libraries to handle cout and cin
-
#include <iostream>
-
using namspace std;
-
-
-
int _tmain(int argc, _TCHAR* argv[]) // looks like an MS thing, but whatever
-
{
-
int number1 = '9' , number2 = '1' , answer ;
-
answer = '9' + '1' ; // why do you not use number1 and number 2?
-
// if you don't use them, why bother declaring?
-
// it doesn't matter, your answer is the same anyway.
-
-
cout << answer;
-
cin.get(); // can't remember how this behaves, but more importantly, I'm not sure why it's here.
-
-
// you need this, you declare int main
-
return 0;
-
}
-
dont see anything about tags ; Do NOT PM questions to individual Experts, Moderators or Administrators
Before you post your question
Things that are generally unacceptable
Use a Good Thread Title
How to ask a question
Posting Homework or Coursework Questions and Answers
Do Not Double Post Your Questions
Once Your Question Has Been Answered
While you are in the forum
How to Respond to a Question
Codes of Conduct
Code of Conduct - For Moderators and Administrators
Guideline to Moderators
This FAQ is meant for those with moderation rights to give them an idea of when it is appropriate to take any given action. It is put in the public domain so that users of the site may see the advice given to our moderators and may post appropriately in light of this information.
If you are a user and feel that a moderator has overstepped their responsibilities in some way please contact an Administrator stating in a clear and calm manner what your complaint is.
Editing, Deleting, Moving, Merging and Splitting Threads
Editing a Thread
Editing a Post
Deleting a Thread
Deleting a Post
Moving a Thread
Merging Two Threads
Splitting A Thread
Response to Class Assignments
Standard Responses to Various Situations
When to ban a user, how long to ban them for
And once again, this is where reading helps. How to ask a question
How to ask a question
Please follow these guidelines when posting questions as submitting clear and concise questions allows those reading to understand your problem and respond more easily.
* Post your question in a relevant forum
* Make sure you are not posting in an Articles section
* Give the relevant Platform, OS and Version information
o In the C/C++ forum this might be Intel/Windows/MSVC++ 6.0 or StrongArm/ThreadX/Greenhills C/C++
o In Access it might just be the version of Access you are using 97, 2003 etc.
* Give as much detail as possible When you post a question or problem, express the situation clearly and concisely and include all relevant information, code used, data used, result expected, result achieved and any error codes or messages that you get as a result.
* Use Clear English to write your question in if possible, try to avoid using abbreviations
* Do not use leet speak or text speak, they are not Clear English
* Make use of the available formatting tags in the forum Use CODE tags around your code as appropriate:
o
o
o - ..C like code goes here..
o [code=html] ..html code goes here.. [/html]
This will preserve white space and use a mono-spaced font making the code easier to read.
* Do not ask people to reply by email or follow up answers with a PM
* Please don't say that a problem is urgent if it's not. If your problem is time sensitive, please give specific time frames e.g. In 3 days, within 24 hours.
* Please try to read your own post after you've posted it. If you can't make any sense of it, it's a fair bet that our experts will struggle and waste time just trying to understand what you're trying to say. Also, if you get bored when you're half-way through reading it because it rambles on endlessly, how will our experts fare?
* If you wish to post a question do not post it in a discussion created by someone else unless it is about exactly the same problem. Please start a new discussion.
* Full list of Code Tag Supported Languages
* Access Forum Specific Guidelines
Be sure you actually click on the link - because I'm posting this in a forum, the code tags are being rendered - the link has them how they are supposed to be.
man, i'm soo dutch , do you know that? i dont understand code tags and all that other stuff.
man, i'm soo dutch , do you know that? i dont understand code tags and all that other stuff.
Dude, I'm sorry, but if you can't read that an understand (or even try to use them), and haven't noticed that it's also on the box to the right of you when you create, edit, or reply to a thread, I can't help you. Maybe one of the other mods can, but I've been trying all day, and it almost seems like you're trying to be difficult.
Good luck
man, i'm soo dutch , do you know that? i dont understand code tags and all that other stuff.
*ahem* I have the Dutch nationality. How about *reading* a bit? What actually
do you see when you have all that information right in front of you? Just a blur
that you wish to ignore? Please *read* and try to *understand* what it's all
about. I know you're from the cut-and-paste generation but you can at least
attempt to understand *what* to cut-and-paste.
kind regards,
Jos
now, i've waited , now i want to ask a question again,
'6' is a character, 6 is an integer.
integers like 2,4,5,..... ,we putt them in int: integer
characters 'A', '4','d',.......we put them in char : character
that means ; char for characters
int for integers
(if string exist: string for letters)
we cannot put characters in int
we cannot put integers in char,
but some people here saying that we can put characters in int???????
how???????????
we cannot put characters in int
we cannot put integers in char,
but some people here saying that we can put characters in int???????
how???????????
By putting chars in ints and vice versa because it can be done. If you had read
at least an introduction text you could and would have known this and what the
restrictions are. Stop asking silly questions over and over again. Sicarie was
patient with you; I am not. I don't want these forums polluted by your illiteracy.
Jos
ok, i'm reading your rulez, but PM , theres writed that i dont must pm (or something) experts, do they mean : dont ask question every minute?
ok, i'm reading your rulez, but PM , theres writed that i dont must pm (or something) experts, do they mean : dont ask question every minute?
PM == Private Message. I am officially warning you now: I don't want to see
any question from you anymore before you can more or less explain what chars
and ints are and what 'A' and 65 mean. I also want you to explain more or less
why ints can be assigned to chars and vice versa.
Now go and read a book; if I see you here before I'll ban you. You have been warned.
Jos
i've readed everything only what i dont understand : Make use of the available formatting tags in the forum Use CODE tags around your code as appropriate: - ..C like code goes here..
[code=html] ..html code goes here.. [/html]
heeyyyy!!! i know everything about these characters and int , but i just dont know why you can put an caracter into an integer!!
hey, i know how to use it!!
hey, i know how to use it!!
This is two; one more and you're out.
Jos
ok, here is the explaning of char; is a character with two apostrofs like ' ' or 'e' or '4'
integer is not a floating point number its like this 1, 2,3....
unsigned int, long int, unsigned long are too types of int but they have more space for numbers
then we have float , for numbers with . like 4,3854535
a type of float is too a double , its bether, and larger
that was the expalning you wanted.
now i can ask again questions??
i really dont understand why this program dont work
// er.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
int number1 = '9' , number2 = '1' , answer ;
answer = '9' + '1' ;
cout << answer;
cin.get () ;
}
that was the expalning you wanted.
now i can ask again questions??
Sure; just behave like a normal human being and all will be fine. First *read*
before you want to ask a question though; reading helps you understand before
you think you have to ask a question; most likely you have found the answer
to your question yourself already.
kind regards,
Jos
ok thanks , i stop asking for today
i really dont understand why this program dont work
// er.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
int number1 = '9' , number2 = '1' , answer ;
answer = '9' + '1' ;
cout << answer;
cin.get () ;
}
what is that _tmain and _TCHAR stuff all about? A proper C/C++ program needs
an int main(int argc, char* argv[]) function.
Also, you should specify the "don't work" part. Most of the repliers overhere are
not psychic. On top of that it should be "doesn't work" (singular form). This is an
international forum and non-native English speakers could be the folks that
could supply you with the best answers if only they could read your question.
kind regards,
Jos
After reading this thread... I am confused, but I think I get your problem.
You expect:
to produce the output:
but instead you get a much larger number or a letter. This is because when you surround a number or character in ' ' it becomes a char, and its integer value is different then its char value.
If you wrote:
You would get the desired output. PLEASE NOTE (In case you do not know, != means does not equal) Banfa 9,065
Expert Mod 8TB
what is that _tmain and _TCHAR stuff all about? A proper C/C++ program needs
an int main(int argc, char* argv[]) function.
That is Microssofts newest version of main and char (or w_char) I have no idea why they feel the need to do this, especially as _tmain is just #defined to main in their headers.
Banfa 9,065
Expert Mod 8TB
ok, here is the explaning of char; is a character with two apostrofs like ' ' or 'e' or '4'
This is not correct. A char is an integer type often it has 8 bits although this is platform dependent and has the range -128 - 127 (or 0 - 255 if char is unsigned on the platform). 'e' or '4' are character constants and have type char in C++ or int in C.
integer is not a floating point number its like this 1, 2,3....
unsigned int, long int, unsigned long are too types of int but they have more space for numbers
then we have float , for numbers with . like 4,3854535
a type of float is too a double , its bether, and larger
You have made similar mistakes here int is a variable type where as 1 is an integer constant and the same for float and 4.38.
I think you are missing another point which is that the computer does not understand or deal with characters like e (or formally the character constant 'e'). Your computer only deals with numbers (and in fact only deals with the numbers 0 and 1 which it uses long strings of to represent larger numbers). 'e' is just the way the computer outputs the number 101 to the screen to make it easier for humans to read when it is instructed to treat it as a character from the execution character set.
When you type 'e' into a program you are really using a shorthand for
'use the value that represents the letter e in the execution character set' -
#include <iostream>
-
-
using namespace std;
-
-
int main(int argc, char **argp)
-
{
-
cout << static_cast<char>(101) << endl;
-
-
return 0;
-
}
-
in some ways the C standard library function demonstrates this better than cout because it doesn't automatically select what it thinks is the correct interpretation of the data is but lets you specify how to output the data so -
#include <cstdio>
-
-
int main(int argc, char **argp)
-
{
-
char c1 = 101;
-
char c2 = 'e';
-
int i1 = 101;
-
int i2 = 'e';
-
-
printf("%c == %d\n", c1, c1);
-
printf("%c == %d\n", c2, c2);
-
printf("%c == %d\n", i1, i1);
-
printf("%c == %d\n", i2, i2);
-
-
return 0;
-
}
-
of course this probably only helps if you are familar with the printf function.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: rusttree |
last post by:
I'm working on a program that manipulates bmp files. I know the offset
location of each piece of relevent data within the bmp file. For
example, I know the 18th through 21st byte is an integer...
|
by: chandy |
last post by:
Hi,
I have an Html document that declares that it uses the utf-8 character
set. As this document is editable via a web interface I need to make
sure than high-ascii characters that may be...
|
by: Xah Lee |
last post by:
Tabs versus Spaces in Source Code
Xah Lee, 2006-05-13
In coding a computer program, there's often the choices of tabs or
spaces for code indentation. There is a large amount of confusion about...
|
by: Susan Rice |
last post by:
I'm comparing characters via
return(str1 - str2);
and I'm having problems with 8-bit characters being treated as signed
instead of unsigned integers. The disassembly is using
movsx ...
|
by: Kulgan |
last post by:
Hi
I am struggling to find definitive information on how IE 5.5, 6 and 7
handle character input (I am happy with the display of text).
I have two main questions:
1. Does IE automaticall...
|
by: =?Utf-8?B?R2Vvcmdl?= |
last post by:
Hello everyone,
Wide character and multi-byte character are two popular encoding schemes on
Windows. And wide character is using unicode encoding scheme. But each time I
feel confused when...
|
by: 2005 |
last post by:
Would it suppress errors?
Is he trying to hide errors in his code?
|
by: Jim |
last post by:
Hi There,
I'm trying to read a file character by character. When I write the
file out, there is one extra character which shows on the screen as a
solid circle with a small question mark in the...
|
by: Anna |
last post by:
I try to put 8 int bit for example 10100010 into one character of type
char(1 octet) with no hope . Could anyone propose a simple way to do
it? Thank you very much.
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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...
| |