I am new to c++ and have a problem with this program. I have one choice weather the person is full time or part time and if they are full time they get on rate if the sale is above or below $ 10000000. The question I have is how to distinguish between part time and full and be able to use it later in the program.
#include <iostream>
#include <cctype>
#include <string>
using namespace std;
bool part_or_full()
{
cout << "What work time status are you part / full? ";
while (true)
{
string s;
cin >> ws;
getline(cin, s);
if (s.empty()) continue;
switch (toupper(s[0]));
{
case 'F': return true;
case 'P': return false;
}
cout << "Thank you but the two options are eith full or part";
}
}
I think this line switch(toupper(s[0])); should be switch(toupper(s[0])) // no semicolon . And I noticed that you created a function named part_or_full (which I assume you would be using in your code) but you didn't call it anywhere. Plus, I think you could use
instead of replicated ifs. You could even use scopes.
Anyway, I'm also a begginer I don't think I can point a direct solution (err, I may also be wrong for what I pointed out!) for your question but I hope I helped you.
Let's wait for someone more experienced than me so he/she can precisely help you out!
if ('F') is almost certainly not what you want.
Any non-zero value (including the character 'F') is interpreted as true. Thus it is a meaningless test here, since it will always be true.