can any of you help me with this? 'm stuck on the part where i have to have the code end when i input "q" i know the while statement would be something like "while num is not 'q'" but how would i translate that into code? cause as of now, if i input q, when the code asks me to enter a number, it repeats "ENTER A NUMBER" forever. and it cause num is an integer
If you can help i'll buy you a 10-15 steam game.
Aaron Carter
...
Anthony Martinez
Did you try turning it off and on again?
Logan Wilson
while (num!=q)
Landon Lopez
do mean the != operator?
Lucas Green
I like boats
Charles Gomez
It's trying to parse 'q' as a double, and crashes the program. You need to say while(num/1 == num) or something like that.
Camden Flores
i actually already tried that it doesn't work because num is a double and q is a string it says "invalid operands of types 'double' and 'const char'
Im not sure what that means.
Jose Ortiz
The ez way is while(num != (int)'q')
Jonathan Wright
Or just create a boolean outside the while and once you get a value set the boolean to true etc....
Justin Roberts
Or maybe (double)((int)'q')
Elijah Campbell
cin to a double actually parses a whole line, so you can't compare it to a character as suggested by 706516869, 706517598, or 706518095
you will have to cin to a string, and then check if the string is 'q'. if it is not 'q', then you will have to convert the string to a number.
if you can't figure this out by yourself, though, why are you taking a programming class?
John Perry
You need to do error catching before you add whatever your num value is to the sum.
So before you execute the sum+=num, you need an if statement. Which states: If (num.type != Double) >or whatever the command that outputs a variable type is Then { Cout: the input must be a number Cin:num }
My steam ID is mcdominate, gimme some cs skins lol
Brayden Jones
Use infinit while loop:
While(true){ // get input If((char)num ==q) break; // do increment }
Place if block before counter, also you should error check to make sure num is actually a number.
Zachary Carter
so you couldn't actually pay anyone to do your homework?
Michael Ortiz
>tfw I cant code worth shit
Christian Cox
What this user says. here's a hint for the conversion. Use stringstream.
don't send anyone a steam gift. This problem is easily googlable.
Eli James
>don't send anyone a steam gift why you gotta do that
Brandon Bell
You're all not worth it. That's why
Connor Nelson
dickhead
James Lewis
...
Angel Cox
oops
Austin Myers
Is the steam gift card still up for takes?
or was this just a fishy bait all along?
Bentley Adams
An internally terminated loop is the way to do it but also an easy way to have a logic fault. But anybody attempting to loop infinitly until a single condition is bet using alpha to numeric conversions is gonna have a bad time eventually.
Reminder that 'q' is a numeric value and "q" is a character array with a single element(or followed by an implicit termination character of you're being a semantic faggot).
While (num != 'q') should work. If not try (double)(int)'q'.
This will force cast the value of q into an integer of your language a shit and then force cast that integer into a double.
Terrible terrible practice but it works.
Michael Russell
Ask for the num before the loop.
Nathan Mitchell
wat?
Ryder Myers
since we're pretty much going for shit programming here why don't you use an if statement asking if the input is q, if true break else the rest of the code.
Xavier Price
dem trips
Chase Kelly
you can't store a char inside a double. you'll want to do a check to see if cin is a char or double using if statements. if it isn't a double, num = 0
Adam Rogers
Also might want to consider what happens when the input is not a 'q' or a double.