C++ question!

WarDemon666

Platinum Member
Nov 28, 2000
2,224
0
0
I have to take in a postal code as a1b2c3 and output it as A1B 2C3

i have attached the code of what I have now, dont know how I could change it

also, how do you get a program to run outside of the visual studio debugger?

thanks!
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
What is POSTAL_CODE? It looks like it's 7, but that doesn't make any sense. A postal code's length is 6. Give POSTAL_CODE a more meaningful name and value.

And you don't need to "change" a char array. You're taking input from cin and putting stuff into another string. Put the space in as you go, instead of adding it afterwards.

And post more of the context. I don't know what type your variables are or anything.

And why use char arrays in C++? That's what std::string is for.
 

imported_jediknight

Senior member
Jun 24, 2004
343
0
0
You mean something like:
turning a,b,c,d (ie, array[0]=a, array[1]=b... ) into a,b <space>, c d?

First off, you need to have an array that is large enough to accomodate everything, including the space. Then

 

WarDemon666

Platinum Member
Nov 28, 2000
2,224
0
0
Originally posted by: BingBongWongFooey
What is POSTAL_CODE? It looks like it's 7, but that doesn't make any sense. A postal code's length is 6. Give POSTAL_CODE a more meaningful name and value.

And you don't need to "change" a char array. You're taking input from cin and putting stuff into another string. Put the space in as you go, instead of adding it afterwards.

And post more of the context. I don't know what type your variables are or anything.

And why use char arrays in C++? That's what std::string is for.

Guess were using it to get used to the char's in class. i dont know... postal code is 6 + 1 for the \0 at the end, according to the teacher...

jediknight:
we arent supposed to use functions yet, and I doubt thats the way she wants me to do it... its prolly something simpler :S

P.S. I know I could have used a function for this, but she does not want us to..

the getch() doesnt work and I dont know why,, any ideas?

Thanks!
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
Originally posted by: WarDemon666
Guess were using it to get used to the char's in class. i dont know...

Well you're also using ".h" filenames for header includes and not using namespaces etc., so basically you're doing old-style c++. Modern c++ was standardized in 1998. I don't get why they still teach that stuff. (well, maybe I do actually)

postal code is 6 + 1 for the \0 at the end, according to the teacher...

Shouldn't it be MAX_POSTAL_CODE, just like the other MAX_* constants it's next to? Naming it POSTAL_CODE makes it pretty ambiguous.
 

WarDemon666

Platinum Member
Nov 28, 2000
2,224
0
0
Originally posted by: BingBongWongFooey
Originally posted by: WarDemon666
Guess were using it to get used to the char's in class. i dont know...

Well you're also using ".h" filenames for header includes and not using namespaces etc., so basically you're doing old-style c++. Modern c++ was standardized in 1998. I don't get why they still teach that stuff. (well, maybe I do actually)

postal code is 6 + 1 for the \0 at the end, according to the teacher...

Shouldn't it be MAX_POSTAL_CODE, just like the other MAX_* constants it's next to? Naming it POSTAL_CODE makes it pretty ambiguous.

haha yeah. didnt even realise I did that lol
 
Aug 3, 2004
35
0
0
Originally posted by: WarDemon666
I have to take in a postal code as a1b2c3 and output it as A1B 2C3

I'm not sure if this is what you mean, but if you just want the outputted zip formatted with as space just add it to the output stream:




 

WarDemon666

Platinum Member
Nov 28, 2000
2,224
0
0
so anyone know why the getch doesnt work?

also, how could I do it when getting the postal code?

Thanks
 

WarDemon666

Platinum Member
Nov 28, 2000
2,224
0
0
Originally posted by: mattg1981
try using cin.ignore();

i use it just to get rid of whats in the buffer, the teacher told us to use getch at the end of the program to ask the user to press any key....

 

WarDemon666

Platinum Member
Nov 28, 2000
2,224
0
0
error defined! :

error C2065: 'getch' : undeclared identifier
Error executing cl.exe.

test.exe - 1 error(s), 0 warning(s)
 

WarDemon666

Platinum Member
Nov 28, 2000
2,224
0
0
Ok i googled again, and i found that you have to include conio.h, but i dont remember the teacher talking about that.. also, now that it actually runs when i type quit it says nothing, it waits for a key and then displays press any key to continue twice..
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |