c++ cout not working :(
hello
i am new at this programming stuff and not that good either lol but when i compile and run my program the cout << "Enter word to rotate: " doensnt show up on the screen. but you are able to type words in and hit enter and it will perform the rotate function, also the program never ends. Code:
#include <iostream> thanks |
Are you trying to change lowercases to uppercases and vice-versa? If so, the difference between lower ASCII and upper ASCII isn't 13, it's 32 and you must extract 32 when you change lowercase to uppercase. Your code works like this:
//define function char rotate(char *letter){ char rep; char *prep = &rep; for(char a = 'a'; a <= 'z'; a++){ if(*letter == a) *prep = a - 32; } for(char a = 'A'; a <= 'Z'; a++){ if(*letter == a) *prep = a + 32; } return rep; } Output.. [baris@rhinox]$ ./a.out Enter word to rotate: DeNeMe dEnEmE[baris@rhinox]$ No idea about not working cout.. everything looks fine to me.. |
instead of <iostream> try <iostream.h>
and if that doesnot work then you could use... using::std cout; using::std cin; TamTam |
Quote:
Code:
using namespace std; Code:
using::std cout; |
well what i was doing was trying to rotate 13 letters in the alphabet of the orignal characters
so if the letter was like 'a' then it would count 13 letters up the alphabet and the result would be the letter 'n' and as you can see in my source, i am using the new iostream with the using namespace std; so i am baffled |
I am about as new at C++ as you. I always used std::cout untill I found out about the using namespace option. So you can try that. It will get very annoying, adding all those std:: when doing alot of coding. After finding out about using namespace, I believe that I read that the compiler will default to namespace std if it doesn't recognize a command. After this, I tried it and it works fine, so there is a second thing to try. Alot of times I don't bother with using namespace std or std:: anymore (and I realize that this is probably considered poor coding).
|
Quote:
The concept you're missing is that ASCII doesn't wrap back to "a" after "z". Any letters after "m" will have to be counted 13 letters down the alphabet. It's strange you're not getting any output from std::cout. How are you running the program? At the command line, using an IDE of some kind, etc? Lyle |
hi,
try using flush after your first cout to make the string show up at once: Code:
cout << "Enter word to rotate: " << flush; |
aight ok this is strang.... i made another file that has the SAME EXACT source as my orignal rot13.cc except this time i named it bla.cc....
- now the cout works but this time any letter after 'm' gets a totally diff asci character as lyle_s said. - before the cout didnt work but it did as i wanted to so that even a letter after 'm' rotated back to the beginning of the alphabet....O_O (according to ascii this is wrong, even though this is what i wanted) so i guess everything should be working as they should be now so now my last question would be is how do i rotate a letter 13 alphabets while staying in the alphabet, so as i wont end up with other funky characters like {,./#$% thanks for the help |
inside your rotate function, replace the statement following the two ifs with the following:
int c = a - 'a'; int d = (c + 13) % 26; *prep = d + 'a'; c is just the index of the letter in the alphabet, and d is doing some modulo arithmetic action. |
ah thanks psiakr3w
|
All times are GMT -5. The time now is 03:22 PM. |