Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,150,827 members, 7,810,179 topics. Date: Friday, 26 April 2024 at 10:35 PM |
Nairaland Forum / Science/Technology / Programming / Don't Know Why This Simple Program Can't Work Well (1102 Views)
Help A Java Newbie With This Simple Java Program / Help On This Simple Script / Please Help With Java Code For This Simple App.. (2) (3) (4)
Don't Know Why This Simple Program Can't Work Well by Nobody: 12:00pm On Jan 17, 2013 |
#include <cstdlib> #include <iostream> using namespace std; double weightInKilograms, heightInMeters, bMI; //variable declarations of height and weight int main(int argc, char *argv[]) { cout << "::::::::::: FROM THE DEPARTMENT OF HEALTH AND HUMAN SERVICES. :::::::::::::\n\n"; cout << " :::::::::::::: Body Mass Index (BMI) CALCULATOR. :::::::::::::::\n\n\n\n"; cout << "enter your weight in kilograms: ";//displays message to get weight cin >> weightInKilograms;//gets the input for weight cout << "\n"; cout << "enter your height in meters: ";//displays message to get height cin >> heightInMeters;//gets the input for height cout << "\n"; bMI = weightInKilograms / (heightInMeters * heightInMeters); //calculates the BMI cout << "your weight in Kg is " << weightInKilograms << "kg \n" << endl; cout << "your height in meters is " << heightInMeters << "m \n" << endl; cout << "your body mass index is "<< bMI << endl; if ( bMI < 18.5) cout<<"you are underweight\n\n"; if ( 18.5 <= bMI && bMI == 24.9) cout << "your BMI is normal\n"; if (25 >= bMI && bMI == 29.9) cout << "you are overweight\n"; if ( bMI >= 30 ) cout << "you are obese!!\n"; cout << "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::" << endl; cout << "DISCLAIMER: Though this calculator is accurate according to the bmi calculation,\but it dosen't put to consideration your body build which may vary the initial\ gotten result. \n"; cout << "&&&&&&&&:::::::::: APP BUILT BY DIKACHI :::::::::::::&&&&&&&&\n" << endl; system("PAUSE" return EXIT_SUCCESS; } //am stil a novice and am studying with the book, c++ how to program 8th edition. i just need corrections to why it is misbehaving |
Re: Don't Know Why This Simple Program Can't Work Well by ciphoenix: 12:07pm On Jan 17, 2013 |
Your control statements should be in the format if ....... else if ...... else if |
Re: Don't Know Why This Simple Program Can't Work Well by ciphoenix: 12:10pm On Jan 17, 2013 |
What errors are shown? They'll give you a hint on where you went wrong |
Re: Don't Know Why This Simple Program Can't Work Well by lordZOUGA(m): 12:38pm On Jan 17, 2013 |
no closing bracket here system("PAUSE" ; |
Re: Don't Know Why This Simple Program Can't Work Well by Nobody: 1:06pm On Jan 17, 2013 |
it didn't show any syntax error, I didn't get any error wen compiling and linking. Just dat the results when i run the program is not the expected result, like i feel itz from the conditional statement dat I got it wrong |
Re: Don't Know Why This Simple Program Can't Work Well by lordZOUGA(m): 1:10pm On Jan 17, 2013 |
Movingcoil: it didn't show any syntax error, I didn't get any error wen compiling and linking. Just dat the results when i run the program is not the expected result, like i feel itz from the conditional statement dat I got it wrongwhat were you trying to do? |
Re: Don't Know Why This Simple Program Can't Work Well by Nobody: 1:37pm On Jan 17, 2013 |
lordZOUGA:okay this is a body mass calculator ie bmi calculator that has values of bmi<18.5 to read as being underweight, 18.5<=bmi<25 is normal, 25<= bmi <30 is over weight, and bmi > 30 is obese, though I did small adjustments to the thing. This is a kind of assignment they gave in the first 3 chapters |
Re: Don't Know Why This Simple Program Can't Work Well by lordZOUGA(m): 1:43pm On Jan 17, 2013 |
Movingcoil: okay this is a body mass calculator ie bmi calculator that has values of bmi<18.5 to read as being underweight, 18.5<=bmi<25 is normal, 25<= bmi <30 is over weight, and bmi > 30 is obese, though I did small adjustments to the thing. This is a kind of assignment they gave in the first 3 chaptersthen you should replace this statement if ( 18.5 <= bMI && bMI == 24.9) and other occurences with if ( 18.5 <= bMI && bMI <= 24.9) |
Re: Don't Know Why This Simple Program Can't Work Well by Temas: 10:27pm On Jan 22, 2013 |
Movingcoil: #include <cstdlib> bro am a novice as well but this is the code in c language i hope it helps. these are the mistakes i was able to see in your code. 1. An if ,else if statement is the best and for testing your conditions. 2.Then the statement should be in the format as shown in my code(i think) 3.float data type i think is the best cos u dealing with decimals here. regards #include<stdio.h> #include<string.h> #include<stdlib.h> float multi(float a,float b) // function prototype { float heightsquare; heightsquare=a*b; return heightsquare; } int main(int argc, char *argv[]) { float weightInKilograms, heightInMeters, bMI; float heightsquare; printf("::::::::::: FROM THE DEPARTMENT OF HEALTH AND HUMAN SERVICES. :::::::::::::\n\n" printf(":::::::::::::: Body Mass Index (BMI) CALCULATOR. :::::::::::::::\n\n\n\n", printf("enter your weight in kilograms:" scanf("%f",&weightInKilograms); printf("\n" printf("enter your height in meters:" scanf("%f",&heightInMeters); printf("\n" heightsquare= multi(heightInMeters,heightInMeters);// function call bMI = weightInKilograms / heightsquare; printf("your weight in Kg is %.1fkg\n",weightInKilograms); printf("your height in meters is %.1fm\n",heightInMeters); printf("your height in square meters is %.1f\n",heightsquare); printf("your body mass index is %.1f\n",bMI); // testing conditions with if then else if if ( bMI < 18.5) { printf("you are underweight\n\n" } else if ( (bMI>=18.5) && (bMI <= 24.9)) { printf("your BMI is normal\n" } else if ((bMI>=25) && (bMI <= 29.9)) { printf("you are overweight\n" } else if ( bMI >= 30 ) { printf("you are obese!!\n" } printf("::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::\n" ); printf("DISCLAIMER: Though this calculator is accurate according to the bmi calculation\n" printf("but it dosen't put to consideration your body build which may vary the initial gotten result.\n" printf("&&&&&&&&:::::::::: APP BUILT BY DIKACHI :::::::::::::&&&&&&&&\n" getchar(); return 0; } |
Re: Don't Know Why This Simple Program Can't Work Well by CodeHouse: 8:38am On Apr 02, 2013 |
Can program it for ya |
(1) (Reply)
45 Useful Javascript Tips, Tricks & Best Practices / Please, Help: Want To Build An Online Learning Platform With Laravel / Shuffling Multidimensional Array Of Values
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 29 |