Skip to main content
gamedev.net
🔒 Locked

Code problem

Started by Penguinzchaseme 4 replies 350+ views
Original Post
Penguinzchaseme
Penguinzchaseme
This code multiplies the number of each letter in a string(a=1 z=26) and checks to see if the modulus of each string divided by 47 is equal. #include <iostream> using namespace std; int main() { char alpha[27]="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; char *UFO, *Group; int n, b=1, c=1; cin>>*UFO; cin>>*Group; for(n=0; alpha[n];n++); { while(*UFO){ if(*UFO=alpha[n])*UFO=n+1; else UFO++; } while(*Group){ if(*Group=alpha[n])*Group=n+1; else Group++; } } while(*UFO){ b=b*(*UFO); UFO++; } while(*Group){ c=c*(*Group); Group++; } if((b%47)==(c%47)){ cout<<"Go"; } else cout<<"Stay"; return 0; } but it only allows me to input the first string(*UFO)-any ideas? [edited by - Penguinzchaseme on April 30, 2003 11:18:55 PM]
When Penguins are chasing you, resistance is futile, give into their demands and they may spare you
andy_fish
andy_fish
yay for homework.

I think the line "cin>>*UFO;" should be "cin>>UFO;" .. because otherwise it will just get one character from cin.

but instead of using char*, you should be using std::string. Yes, using STL is painful at first, but it is worth it.
Sneftel
Sneftel
quote:
Original post by Anonymous Poster
Back in high school on those POS computers that would happen to me sometimes too. The way i got around it was i put some sort of delay between the 2 cin>> s because when I pushed [enter], both of the cin>> took the enter. So i did a cheap little for(i=0;i<500;i++); in there.

they where crappy celerons with boreland 4 on them. That what you have???

God i hated those computers...

I dont think that a uninitialized varaible would cause that problem because you are setting a variable.

Another thing I noticed is that you are doing

cin>>*charPrt;
but i remeber doing
cin>>charPtr; without the * because I think you are inputting the address and not the text mb???

Those are the only ideas i have.


Ye gods. Please, just... just ignore everything that AP just said. About 90 percent of it is wrong. Yes, your problem is an uninitialized variable: Your pointer does not point to valid memory at the time it is dereferenced. a std::string will enable you to not worry about this.


How appropriate. You fight like a cow.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.