Click here to Skip to main content
15,910,661 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello, I'm using a DEV C++ for my program. I send the file to my friend but when he run it, it wasn't working at all. He said "because of getch()". But when I run the program it is totally working.

What I have tried:

I haven't tried anything yet because my friend is kinda far away. We only see during school days and right now we are on a holiday break
Posted
Updated 30-Oct-18 22:34pm

You should avoid using getch, it is a not standard C/C++ function. As an alternative, have a look at cin.get, but it really depends on your exact scenario (you didn't report it).
 
Share this answer
 
Comments
Member 14037488 31-Oct-18 4:57am    
the code is this

#include <iostream>
#include <cstdlib>
#include <string>
#include <conio.h>
using namespace std;

int main (){

char pin[5], orpin[5], orpin2[5], orpin3[5]; //character sila, kase pag int iba yung lumalabas
int i=0, j=1, k=3, k1 = 1; //ginamit ko sa loop as counter parang ganon
char letter, y; // yung letter para sa letter na pipiliin B, W, D, X ... yung y para sa YES and No
int money1 = 10000, wd1, dp1; //para sa 1st acc
int money2 = 5900, wd2, dp2; //para sa 2nd acc
int money3 = 990, wd3, dp3; //para sa 3rd acc


orpin[0] = '1'; orpin[1] = '9'; orpin[2] = '9'; orpin[3] = '9'; //1st acc - PIN 1999
orpin2[0] = '3'; orpin2[1] = '1'; orpin2[2] = '2'; orpin2[3] = '4'; //2nd acc - PIN 3124
orpin3[0] = '7'; orpin3[1] = '2'; orpin3[2] = '5'; orpin3[3] = '9'; //3rd acc - PIN 7259




while (j <= 3){ //buong program ay while loop

cout << "ENTER PIN\t::\t"; //dito mag-iinput ng PIN
for (i=0;i<=3;i++){ //loop hanggang apat lang
pin[i]=getch(); //yung getch daw para makuha yung na-input na char tas yung [] ganyan para ma-store yung input sa array
if ((pin[i] >= '0') && (pin[i] <= '9')){ //para malaman kung numbers ba yung input .. kaya may apostrophe kase char sya hindi siya int
cout << "*"; //ito yung lalabas pag may ininput yung user
} else {
cout << "*";
}
}




the code is kinda long so i copy paste the first part
just ignore the commentaries // hehe .. thanks :)
We can't answer that; or even begin to - we can't see the code, we can't see your screen, we can't see your friend's screen, we can't access your HDD, and we can't read either of your minds!

You and your friend need to learn how to report a problem, and how to ask a question: at the moment, you have broken down in the middle of nowhere, called the garage (us) and said "It don't work. My friend says it the bit which goes round" and put the phone down.
How long do you think it will be until the garage arrives with the right parts to fix your car?

Try reading here: Tips for asking technical questions that result in fast, useful solutions | Opensource.com[^] and then think to yourself "how much did my friend actually tell me? What symptoms did it show? Why does he think it's 'because of getch()'?"
If he didn't give you any real info, what makes you think that anyone else can help you with even less?
 
Share this answer
 
Comments
Member 14037488 31-Oct-18 4:57am    
the code is this

#include <iostream>
#include <cstdlib>
#include <string>
#include <conio.h>
using namespace std;

int main (){

char pin[5], orpin[5], orpin2[5], orpin3[5]; //character sila, kase pag int iba yung lumalabas
int i=0, j=1, k=3, k1 = 1; //ginamit ko sa loop as counter parang ganon
char letter, y; // yung letter para sa letter na pipiliin B, W, D, X ... yung y para sa YES and No
int money1 = 10000, wd1, dp1; //para sa 1st acc
int money2 = 5900, wd2, dp2; //para sa 2nd acc
int money3 = 990, wd3, dp3; //para sa 3rd acc


orpin[0] = '1'; orpin[1] = '9'; orpin[2] = '9'; orpin[3] = '9'; //1st acc - PIN 1999
orpin2[0] = '3'; orpin2[1] = '1'; orpin2[2] = '2'; orpin2[3] = '4'; //2nd acc - PIN 3124
orpin3[0] = '7'; orpin3[1] = '2'; orpin3[2] = '5'; orpin3[3] = '9'; //3rd acc - PIN 7259




while (j <= 3){ //buong program ay while loop

cout << "ENTER PIN\t::\t"; //dito mag-iinput ng PIN
for (i=0;i<=3;i++){ //loop hanggang apat lang
pin[i]=getch(); //yung getch daw para makuha yung na-input na char tas yung [] ganyan para ma-store yung input sa array
if ((pin[i] >= '0') && (pin[i] <= '9')){ //para malaman kung numbers ba yung input .. kaya may apostrophe kase char sya hindi siya int
cout << "*"; //ito yung lalabas pag may ininput yung user
} else {
cout << "*";
}
}




the code is kinda long so i copy paste the first part
just ignore the commentaries // hehe .. thanks :)
Patrice T 31-Oct-18 6:02am    
Use Improve question to update your question.
So that everyone can pay attention to this information.
Richard MacCutchan 31-Oct-18 6:09am    
You never increment the value of j in the outer loop. And your if statement serves no purpose.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900