Clearing Multiple Variables

Hello,

I am new to C++ programming, teaching myself as I go along. I am currently writing a program where the user can pick multiple options which modify multiple variables. I included a "reset" button, which will reset all of the variables (float type) back to 0.

Herin lies my question: Is there a neater, more concise way to reset variables to a default value than individually reassigning their value? (a=0; b=0; c=0; etc etc)

Thanks for the help!
a=b=c=0;
hamsterman: a=b=c=0;


This would still be rather unwieldy. I have a few hundred variables. Is there a way to define a group of variables perhaps? Then set that group of variables to a default assignment?
Never mind.
Last edited on
closed account (D80DSL3A)
Is there a way to define a group of variables perhaps?

An array may be useful here.
int arr[100] = {0};// array of 100 integer variables with all initialized = 0.

You can use a loop to reset the values later.
1
2
for(int i=0; i<100; ++i)
    arr[i] = 0;
When you say you have a few hundreds of variables, I hope you mean you have an array.. If you don't, do consider that option.
When you have an array you could use http://www.cplusplus.com/reference/algorithm/fill/ or http://www.cplusplus.com/reference/clibrary/cstring/memset/
Hmm interesting, I may be able to make it work using an array, I need to mess with it.

Thanks for the replies!
Topic archived. No new replies allowed.