C++ if else problem, please look

posted by .

It compiles but it doesn't work. can you tell me what i did wrong?

//Sonny Hinh, variable program, assignment 2
#include <iostream>
using namespace std;

int main ()
{ char gender;
int age, bmi, dose1, dose2;
double dose3, dose4;
dose1 = bmi * 2;
dose2 = bmi * 2 + 13;
dose3 = bmi * 2 * .95;
dose4 = bmi * 2 + 13 * .95;
cout << "Enter age: ";
cin >> age;
cout << "Enter BMI: ";
cin >> bmi;
cout << "Enter sex (M or F): ";
cin >> gender;
if (gender == 'M')
{ if (age < 12)
{ cout << "\nDose is: " << dose1 << " units" << endl;
{ cout << "\nDose is: " << dose2 << " units" << endl;
{ if (age < 12)
{ cout << "\nDose is: " << dose3 << " units" << endl;
{ cout << "\nDose is: " << dose4 << " units" << endl;
return 0;

  • C++ if else problem, please look -

    In general, the program "does not work", it can mean a lot of things:
    - it does not give any output,
    - it does not give the right answer,
    - it gives an execution error,
    - it reboots the computer
    Each situation calls for a different solution.

    In your particular case, I believe it does not give the right answer.

    The computer program executes in sequence. The doses are defined with reference to BMI, when BMI is not input by the user. So in the best of cases, BMI is output as zero (for Java) and probably BMI UNDEF in the case of C++.

    All you need to do is to define the different doses AFTER the entry of values by the user, probably just before the "cout" statements.

    If you would like them defined at the beginning, you could define them as methods (procedures).

    If there are other "symptoms", please specify and post any time.

  • C++ if else problem, please look -


Respond to this Question

First Name
School Subject
Your Answer

Similar Questions

  1. C++

    Can anyone help me with my c++ program? Its a program I have to write using structs and arrays and i'm stuck. If anyone can help can you post back and I'll show you what i've got and maybe you can tell me why its not working correctly.
  2. C++ Programming

    Can any1 please fix this c++ source problem /*Circle Are program Calculates the area of a circle using the formula A=pi * r * r Sonny Hinh, 1/23/08 #include <iostream.h> int main() { cout << "-Calculate the area of a circle-" …
  3. C++ Programming

    I have to redo programming exercise 5 of chapter 9 using dynamic arrays. but I have the information but I don't know how to use it in a dynamic arrays please help. //Chapter 9: Programming Exercise 5 #include <iostream> #include …
  4. programming

    Having trouble with this program running, can anybody help solve my problem: #include <stdio.h> #include <stdlib.h> #include <string.h> void draw_x(int width, int height); int main(int argc, char *argv[]){ int width, …
  5. programming C++

    Write a program that reads test scores up to 30 into an array. sentinel will stop when -1 is entered. Write functions that: 1. read the scores into arrays 2. computes the distribution based on whether they are As, Bs and so on 3. find …
  6. computer science

    9.10: Reverse Array Write a function that accepts an int array and the array’s size as arguments. The function should create a copy of the array, except that the element values should be reversed in the copy. The function should …
  7. Computer

    on C++, I want to make an operation like " 2x + y - z ", I wrote something like that but I can' t get the result, where is my mistake?
  8. Fund of programming 1

    Complete the following C++ program. The program should compute and output the Celsius value corresponding to the given Fahrenheit value. //************************************************ // Celsius program // This program outputs …
  9. Programing

    Write a full program that reads in an arbitrary sequence of integers from the standard input, and writes them to the standard output in sorted order and with all duplicates removed. You may assume the input contains at most 100 integers …
  10. C++

    (4 points) Identify the errors in the following statements. int* p = &44; - i think the star is the error because pointers are supposed to be like *p?

More Similar Questions