Ok, so I have to do a program that takes your weight, and determines the number of calories per day you need to maintain that weight based on two things: being male or female and being active or inactive.
I've tried to get the damned thing working with both case selection and if/else. I suspect its me doing something very stupid, but right now my C++ compiler growls at me with
"c
c\tut09\t9appe07e switched.cpp(38) : error C2450: switch expression of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' is illegal
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Error executing cl.exe."
Here's my code.
I've tried to get the damned thing working with both case selection and if/else. I suspect its me doing something very stupid, but right now my C++ compiler growls at me with
"c
c\tut09\t9appe07e switched.cpp(38) : error C2450: switch expression of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' is illegalNo user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Error executing cl.exe."
Here's my code.
Code:
#include <conio.h>
#include <iostream>
#include <string>
using namespace std;
//function prototypes
void activeString(string&, int, int);
void nonActiveString(string&, int, int);
int main()
{
//declare variables
int calories = 0;
int weight = 0;
string sex = "";
string active = "";
//input
cout << "Please enter your weight in pounds ";
cin >> weight;
cout << "Please enter your gender (m) for Male or (f) for Female ";
getline(cin, sex);
//cin >> sex;
cout << "Please state moderate activeness (a) or inactiveness (i) ";
//cin >> active;
getline(cin, active);
//switch
switch (active)
{
case 'a':
case 'A': activeString(sex, weight, calories);
break;
case 'i':
case 'I': nonActiveString(sex, weight, calories);
break;
default: cout << "activeness error" << endl;
}//end switch.
getch();
return 0;
} //end of main function
//*PROGRAM DEFINED FUNCTIONS*
//active string
void activeString(string &sex, int weight, int calories)
{
if (sex == "m" || sex == "M")
{
calories = weight * 15 ;
cout << "You need " << calories << "to maintain your weight " << endl;
}
else if (sex == "f" || sex == "F")
{
calories = weight * 12 ;
cout << "You need " << calories << "to maintain your weight " << endl;
}
else
cout << "calc error" << endl;
}
//non active string
void nonActiveString(string &sex, int weight, int calories)
{
if (sex == "m" || sex == "M")
{
calories = weight * 13 ;
cout << "You need " << calories << "to maintain your weight " << endl;
}
else if (sex == "f" || sex == "F")
{
calories = weight * 10 ;
cout << "You need " << calories << "to maintain your weight " << endl;
}
else
cout << "calc error" << endl;
}
//end