I have a switch statement where it counts how many times I input the number 1. However I just want it to store the increment the value when i put one digit which is 1, because when I put a number like 521134 it will still count the two 1 in the number 521134. How can I make it count the number 1 as in one digit only. If this is unclear I can post the code.
I still don't understand your question or your class.. What is calc salary and get salary supposed to be doing? Also AFAIK std::get is for one character only so might be hard to do -1 that is two characters. You could use >> and that will get input into a white space which would allow -1. Also on your set salary function the second variable is pointless imo. You can just do
1 2 3 4 5
void set_salary()
{
std::cout << "Please enter salary: " << std::flush;
std::cin >> salaray; //assigns value to the private in class
}
Then for your getmessage function you can just output the private variable.
1 2 3 4
void get_message()
{
std::cout << "I am a message with a salary of " << salary << std::endl;
}
*edit also please use code tags <> in the format section or type
[code][/code]
around your code.
Your switch should also be case 1: not case '1': since code is an int not a char. If you wanted to use a char as a case you could do case '1' - '0': I suppose though.
Yeah sorry didn't know how to do that. until now. I need calc salary just in case im gonna do a calculation. I won't use it though. The get salary is to return the value of salary. Because I learned that when u set a variable in private you need to get it my making getters and setters functions.
I fixed the the switch while loop and still it is not working.
you still have case '1': instead of case 1:........Also you have two "getters" and btw getters/setter's aren't very good you should ask for input before creating the object then use an initializer list. ex:
The problem was I had case '1': instead of case 1: you are right. I also changed the two getters I had and made one. So much more organized now. I thought to get something you should always return it, that's why I had it.
Thanks a lot that made everything much better.