Actually, a switch statement is usually resolved to an if-else statement by the compiler, unless there are hundreds of conditions. In that case, however, the compiler would resolve it to JMP instructions.
1 2 3
|
const double packadge_A = 9.95, packadge_B = 14.95, packadge_C = 19.95;
int users_packadge;
double hours_used, hours_to_pay, hours_to_pay_in_money;
| |
I don't know what that's supposed to represent, but y
ou can start by throwing that into a data structure and call it "member_data" (or somthing similar; really whatever you want).
If you're going to store constants (like prices) make them defaults or somthing... or you can use template meta-programming to have compiler-time resolution and eliminate the variables alltogether.
You can write another function and call it "menu" or whatever you want. There's no need for everything to be within main, and it would make it easier for you to expand upon your work in the future, should you choose to do so.
I would choose a different approach to the code within the if-statements that act based on the "package" chosen
. You might have a data structure called "package", and it stores an integer, price, and whatever else is associated with a "package". You can then declare constants within an array, and enumerate them as names:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
//this is just pseudo:
typedef struct package package;
//package has constructor: package::package(const double& price, const double& hour_limit)
//we try to avoid global constants by having a function return them instead.
inline std::vector<package> avail_packs()
{
return std::vector<package>({
package(5, 10),
package(9.9, 20),
package(15, 30)
});
}
enum package_type
{
package_a = 0,
package_b
package_c
};
//....
//easy peasy
std::cout<< "package A costs: $"<< avail_packs()[package_a].price<< std::endl;
| |
Hope this helps.