Can any of you help me with this?

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.

...

Did you try turning it off and on again?

while (num!=q)

do mean the != operator?

I like boats

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.

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.

The ez way is while(num != (int)'q')

Or just create a boolean outside the while and once you get a value set the boolean to true etc....

Or maybe
(double)((int)'q')

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?

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

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.

so you couldn't actually pay anyone to do your homework?

>tfw I cant code worth shit

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.

>don't send anyone a steam gift
why you gotta do that

You're all not worth it. That's why

dickhead

...

oops

Is the steam gift card still up for takes?

or was this just a fishy bait all along?

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.

Ask for the num before the loop.

wat?

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.

dem trips

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

Also might want to consider what happens when the input is not a 'q' or a double.

Good luck OP.