4 Replies - 403 Views - Last Post: 24 September 2012 - 05:58 AM Rate Topic: ***-- 1 Votes

#1 mshumann  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 2
  • Joined: 23-September 12

Won't calculate after I ask to enter exercise amount?!?

Posted 23 September 2012 - 01:36 PM

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            double weight = 0;
            double height = 0;
            double years = 0;
            double sex = 0;
            double BMR = 0;
            double exercise = 0;
            double calories = 0;
            double meal = 0;
            double answer = 0;
            Console.WriteLine("Welcome to Matt's Calorie Counter!");
            Console.WriteLine("Let's get started!!! First we have to calculate your BMR.");
            Console.WriteLine("Tell me your weight in pounds: ");
            weight = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("Tell me your height in inches: ");
            height = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("Tell me your age in years (I won't tell a soul): ");
            years = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("What sex are you? Enter 1 for Male or 2 for Female: ");
            sex = Convert.ToDouble(Console.ReadLine());
            if (sex == 1)
            {
            Console.WriteLine("Your BMR is  " + (66 + (6.23 * weight) + (12.7 * height) - (6.8 * years)));
            }
            else
            {
            Console.WriteLine("Your BMR is " + (655 + (4.35 * weight) + 4.7 * (height) - (4.7 * years)));
            BMR = Convert.ToDouble(Console.ReadLine());
            }
            
           
            Console.WriteLine("Choose your level of exercise to calculate your caloric needs to maintain your weight. ");
            Console.WriteLine("1. You don't exercise.\n2. You engage in light exercise 1-3 days a week.\n3. You exercise moderately 3-5 times a week.\n4. You exercise intensely 6-7 days a week.\n5. You exercise intensely 7 days a week and have a physically active job.\n");
            exercise = Convert.ToDouble(Console.ReadLine());
            do 
            if (exercise == 1)
            {
                
                Console.WriteLine(" To maintain your weight your maximum calorie intake should be:" + (BMR * 1.357));
                calories = (BMR * 1.357);
            }
            else if (exercise == 2)
            {
                
                Console.WriteLine(" To maintain your weight your maximum calorie intake should be: {0}", calories = (BMR * 1.55));
                calories = (BMR * 1.55);
            }
            
            else if (exercise == 3)
            {
                
                Console.WriteLine(" To maintain your weight your maximum calorie intake should be: {0}", calories = (BMR * 1.357));
                calories = (BMR * 1.357);
            }
            else if (exercise == 4)
            {
                
                Console.WriteLine(" To maintain your weight your maximum calorie intake should be: {0}", calories = (BMR * 1.725));
                calories = (BMR * 1.725);
            }
            else
            {
                
                Console.WriteLine(" To maintain your weight your maximum calorie intake should be: {0}", calories = (BMR * 1.9));
                calories = (BMR * 1.9);
            }
            calories = Convert.ToDouble(Console.ReadLine());
            
            Console.WriteLine("your calories lefts for the day are :", calories);
            Console.WriteLine(" Would you like to enter a caloric value for a meal or snack? Enter 1 for yes and 2 for no");


MOD EDIT: Added code tags. When posting code...USE CODE TAGS!!!

:code:

This post has been edited by JackOfAllTrades: 23 September 2012 - 02:21 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Won't calculate after I ask to enter exercise amount?!?

#2 mshumann  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 2
  • Joined: 23-September 12

Re: Won't calculate after I ask to enter exercise amount?!?

Posted 23 September 2012 - 01:43 PM

The "do" before the else if statement is not supposed to be there.I was trying something else and did not delete all the way.
Was This Post Helpful? 1
  • +
  • -

#3 November-06  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 404
  • Joined: 04-January 11

Re: Won't calculate after I ask to enter exercise amount?!?

Posted 24 September 2012 - 02:53 AM

Try using .ToString() to non-string variables and equations when displaying.

Console.WriteLine("your calories left for the day are :", calories.ToString());



Also, try to change this line

Console.WriteLine(" To maintain your weight your maximum calorie intake should be: {0}", calories = (BMR * 1.357));



to

Console.WriteLine(" To maintain your weight your maximum calorie intake should be: {0}", (BMR * 1.357).ToString());



Try to do the same to lines similar to this.
Was This Post Helpful? 0
  • +
  • -

#4 rgfirefly24  Icon User is offline

  • D.I.C Lover
  • member icon


Reputation: 285
  • View blog
  • Posts: 1,503
  • Joined: 07-April 08

Re: Won't calculate after I ask to enter exercise amount?!?

Posted 24 September 2012 - 05:44 AM

you are attempting to set a variable within all of your calls to Console.WriteLine. Remove all of the instances of calories = from your Console.WriteLine calls.

EX:
Console.WriteLine(" To maintain your weight your maximum calorie intake should be: {0}", calories = (BMR * 1.357));



should be


Console.WriteLine(" To maintain your weight your maximum calorie intake should be: {0}", (BMR * 1.357));


This post has been edited by rgfirefly24: 24 September 2012 - 06:08 AM

Was This Post Helpful? 1
  • +
  • -

#5 Curtis Rutland  Icon User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4559
  • View blog
  • Posts: 7,980
  • Joined: 08-June 10

Re: Won't calculate after I ask to enter exercise amount?!?

Posted 24 September 2012 - 05:58 AM

@November-06, there's no real need to add ToString method calls in a Console.WriteLine call. Parameters will automatically have their ToString methods called, because Console.Out is a TextWriter.
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1