sup Sup Forumsrothers, i need some help i must work a program that recognize numbers separately to multiplicate it, having only one data entering
ex.: int a, b, c, d, e; >printf("enter with your id") 54321 >scanf("%d""%d""%d""%d""%d", &a, &b, &c, &d, &e);
*then i need to take each number to multiplicate em like 5*6+4*5+3*4+3*3+1*2
>the problem i dont know hot to select each number separately
pls, help me b
Anthony Watson
getc() is your friend
Austin Ross
You mean getch()?
Christian Wilson
Or modulos and divide by 10 to get each digit of the number
Asher Carter
Yes
Xavier Cooper
input it as a whole string and then isdigit every letter and act accordingly if it is (convert it to int and send it to int array or something where you can work with it), if there are 2 or more digits in a row just merge them and convert to number
Owen Kelly
That would imply dynamic memory usage, with malloc and realloc as you dont know how large the string is gonna be. getch() is best bet, or maybe modulos + division to get every digit of the number
Ethan Nelson
Should i use getch or modulo?
Anthony Edwards
you can use getch() in a loop and check for the return character so that you can exit the loop. And do the operations while in the loop
Connor Hernandez
Can you pre write it to me? As an example
Christopher Watson
Hmm, im starting to get your explanation
Anthony Kelly
getch() - now deprecated has been moved over to _getch(). They are either retarded or trolling you. If you want help add me on discord at: Kill_Maddie#1265
Charles Stewart
Int x;
x=54321;
while (x>0) { a= x%10 }
Luke Gutierrez
Also why are you using Dev C++? Not exactly a good IDE... no offense
Jace Nelson
These guys are retarded and suggesting a deprecated function call... holy shit you guys are fucking stupid. Use _getch() >_>
Caleb Cook
With modulus + divide int digit;
while(x > 0) { digit = x % 10; x = x / 10; }
Jonathan Mitchell
c++ pic.. c code?
Samuel Walker
You both are what's wrong with programmers today. I said getch() cause that is what i remember from the last time i touched C. If it's indeed replaced by _getch() (which i assume it does the same fucking shit), then why are you saying it's not a valid solution? KYS pls
Colton Myers
not optimized at all, just wrote it in 1min
Joseph Lewis
So, i must use getch in a loop to select each number separately then make the multiplication? Sorry for my bad english
Leo Rogers
int inputs[5];
for i = 0 to i = 4 inputs[i] = getch - '0';
int output = 0; for i = 0 to i = 4 output += (i +1) * inputs[i]
Sebastian Nguyen
Are we doing c or c++
Dominic Parker
C++
Adrian Gray
Deprecated functions are functions which are intended to be removed at one point or another. Using getch() is a short-term solution as it very well may be removed. Also deprecated functions tend to have more problems than their counter-parts. It would be like saying it is reasonable to use the memcpy() function despite it being one of the easiest ways to fuck things up. What have you done for the industry? Fuck off
Juan Gutierrez
getch(), or _getch() as pointed by other users automatically captures each character from the keyboard as soon as you press that key. So it would be something like
char c;
while((c=_getch()) != "return character") {
transform c to a number and store in a variable and then do the operations you need to do.
}
Take note that "return character" means you gotta get the code for the return key on the keyboard, which i do not remember right now.
Nicholas Hernandez
Honestly I am not sure how you typed that without feeling ashamed. Please educate yourself.
William Hill
Dude....
It... does... the .... same... fucking... thing...
Change the fucking getch() to _getch() since you are worried so much about that and be done with it. The essence of the solution is the same, dumbfucks. That is what i am trying to say.
Michael Clark
cin >> a >> b >> c >> d; then you want to multiply them all together??
Cooper Brown
Also, who gives a shit if it is deprecated. IF you ever went to a college or even studied it you would know people in college, even professors, don't give a shit whether it's deprecated or not. So, unless you are coding for something you are going to sell, you don't care about that bullshit. Just use it and get it done. Kids these fucking days who think they know what they are fucking talking about.
Hunter Rodriguez
So you think it is appropriate to get in the habit of using deprecated functions? What if he goes and works for an industry and writes his code with getch() just because it solves the problem? Then what happens when they remove getch() and you are asked to update your code to C++ 12? Now let's say he used to 100 times in his code. That means 100 lines are broken on update.. how do you not get this?
Kayden Wood
You think professors letting students get away with bad habits makes those habits a good thing? Jesus you are stupid. It can cause issues if C++ removes the getch() function.
Brayden Gutierrez
Read
What i am saying is that it's perfectly OK to do this for academic purposes. What you should care about is the algorithm, that you manage to get at the solution of a problem. Obviously, for real world applications, you want to be more rigorous with what tools you are going to be using.
Asher Torres
Ty all guys
Xavier Watson
can you fags stop arguing over a goddamn c++ function
Ian James
Why not just promote good habits while learning? Your premise is flawed. I'm saying learning bad habits is a BAD idea.
Noah Wood
> asking for homework help on a Tibetan throat-singing imageboard
Ryder Hughes
You will soon learn, that all tools do get deprecated. Have fun when your _getch() gets replaced with alphagetch() and you still get the errors you so worry about. If you are taking so much time in memorizing a function name, you are doing something wrong. You should get in the habit of updating your knowledge when coding for production value, paying more attention to algorithms than function names. My solution works. Your _getch() does the same shit as the getch() i remember, and guess what? The algorithm, and thus the solution, won't change.
John Adams
Also people need to stop including the std namespace. It is a terribly stupid way to go about writing code. takes 1/16 of a second longer to type out std::cout
Brandon Perez
int main() { string s; getline(cin,s); int sum = 0; for(int i=0;i
Zachary King
You keep falling back on "it works" as a premise. We are not discussing if it works or not rather which thing is better to use. I do not memorize anything in programming. I've just programmed enough that I remember the content. You dumb fucks keep promoting bull shit because you have limited practice in C++. It is embarrassing for you.
Bentley Davis
Also another problem with those commenting is they are not including spaces for readability. Holy shit learn to put a fucking space.
Lincoln Murphy
Create a macro that maps getch() to _getch(). Done.
Jordan Torres
You see, the problem is that you care about stupid shit that is trivial. This is obvious a homework for a class that may be, AT MOST, for a college level course. And you haven't said a single thing that may actually make his algorithm better, like checking that the character _getch() captures is a number and not an alpha character so that it can skip it. Yet here you are arguing about deprecated bs that no one cares about at a college level.
I am not promoting anything, i just mentioned getch() because that is what i remember from memory. I am too busy with higher level languages that do all the crap you worry about for free and without me having to think about it.
Nicholas Bennett
Well no that would be retarded since most modern IDEs you can just replace all with. Your solution although a solution is a dumb one.
Liam Johnson
...
William Walker
scripter... okay I am done talking with you. That is utterly embarrassing. Enjoy your at most shitty 40 dollar an hour pay.
Liam Perry
So you admit there are two simple solutions to this non-issue. Yet you continue to argue that it is a problem. Ok m80.
Asher Roberts
If you are doing the same loop 3 times why are you not just using recursion and injecting functionality?
Owen Butler
Java is scripting? Ruby is scripting? C# is scripting?
Isaiah Kelly
One solution is better than another solution. The premise is over which one to use not which one works. They both work. Duh.
Christopher Jackson
every loop is recursion
Aiden Jackson
Ty bro, very much (:
Jaxson Perez
Holy shit you don't understand run time environments. This is just going down hill.
it's a shit IDE, if you must use one use Visual Studio, or if you want something more lightweight use code::blocks
Juan Lee
No shit sherlock. AKA the solution. Nested for loops.
Samuel Barnes
>runtime environment ...Annnnnnnnnnnnd i think, we that post, can safely conclude that you are a moron. Peace out.
Xavier Barnes
It is you dumb fuck. Just google it. Holy shit you are top tier retarded.
Jaxson Moore
Thanks for pointing that out. Most of these people seem retarded as hell.
Easton Lopez
have you fucks never heard of atoi()?
Henry Bennett
The INITIAL "premise" is your argument that using getch() is a problem. I and others argue that it is not an issue, especially given the requirements in this case. Who cares which solution works best if getch() were removed? The point is that, as you have admitted, multiple simple solutions exist.
Jayden Sanders
Recursion is not a programming exclusive term. All it stands for is a repetitive procedure. Your retarded bait where you say for loops are recursion thinking they are not recursion is stupid as they are recursion.
Colton Morris
kek Google what exactly? Keep digging that hole, faggot. Watching retards struggle is fun.
Grayson Sullivan
Yes but my solution is better. This is not a hard concept.
Tyler Wright
That java is in fact a scripting language. This is not something, someone that understands programming would debate. You are telling me it is not a scripting language?
Cameron Williams
Or be a man and use emacs for everything
Daniel Johnson
Java is a compiled language. A compiler compiles it into byte code which is fed to a JIT compiler at runtime to transform it into machine code.
Javascript is a scripting language, though the two have little in common other than the name...
Isaac Morris
>>Sup Forums
Isaiah Hughes
>Java >scripting language
Oh boy. Are you thinking of JavaScript?
Juan Rivera
why am i banned
Sebastian Collins
Cuz ur gay
Lincoln Jenkins
>Yes but my solution is better. Not necessarily. It depends on the program requirements. If you're working on a program that requires a costly audit for each individual file and you do a find/replace on hundreds of files, your manager is going to show you the door and give me your job when I tell him that I could have made the fix by modifying a single file.