I wrote this code, and I'm having a little problem with it. The point of the code is for the user to enter a desired number, then that number gets subtracted by 45 then dived by the percentages and all that dived by 2.
Also I dont know how to switch the percantage. For example I want the user to type in a percentage for the weight to be divided by. But instead the user to type in .5 as 50%, I want the user to type in 50, 60 or 70. And the program knows to conver that into .5, .6 or.7 as percents.
Also the loop is not working to well. The ( cout<< "Invalid response " << endl; ) line comes in everytime I say yes and its not suposed to come in. Its only suposed to come in if I enter a different word besides yes or no. But it comes everytime I enter yes. And if I enter a diferent word besides yes or no the program goes crazie.
Whats going on here?
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int weight;
int barr = 45;
double percentage;
string response;
bool good = false;
while (!good)
{
cout << "Enter the weight you want calculated."<< endl;
cin >> weight;
cout << "At what percentage do you want to callculate?" << endl;
cin >> percentage;
cout << "Your weight of " << weight << " at " << percentage
<< " % " << " = ";
if ( percentage == 50 )
cout << ( ( (weight - barr ) * percentage ) /2 ) << endl;
else if ( percentage == 60 )
cout << ( ( (weight - barr ) * percentage ) /2 ) << endl;
else if ( percentage == 70 )
cout << ( ( (weight - barr ) * percentage ) /2 ) << endl;
else if ( percentage == 80 )
cout << ( ( (weight - barr ) * percentage ) /2 ) << endl;
else if ( percentage == 90 )
cout << ( ( (weight - barr ) * percentage ) /2 ) << endl;
cout<< "Do you want to enter a different percentage? Yes | No " ;
cin >> response;
if (response == "Yes" || response == "yes " || response == "No"
|| response == "no" )
{
good = false;
}
else
{
cout<< "Invalid response " << endl;
}
if (response == " No" || response == "no" )
{
break;
}
}
system("PAUSE");
return EXIT_SUCCESS;
}