Skip to main content
gamedev.net
🔒 Locked

Help with a program

Started by ObTsu Nov 4, 2004 at 9:28 PM 7 replies 600+ views
Original Post
ObTsu
ObTsu
Hey, I'm a beginning programmer writing this little piece for practice. It finds the BMI of someone. I get a ton of errors when I compile it. Thanks for any help. Oh, and I don't want to completely rewrite it, if possible. I'd like it to stay essentially the same.
 #include <iostream>

int convert(int foot, int inch);

int convertWeight(int pound);

int convertFinal(int weight, int height);

using namespace std;

    int foot;
    int inch;
    int pound;
    int height;
    int weight;
    int BMI;
    int finalBMI;
    int finalHeight;
    int finalWeight;

int main() {
    
    
    cout << "Input your height in feet\n";

    cin >> foot;

    cout << "Input your height in inches\n\n";

    cin >> inch;
    
    height = int convert(int foot, int inch);
    
    cout << "Input your weight in pounds\n";
    
    cin >> pound;
    
    weight = int convertWeight(int pound);
    
    BMI = int convertFinal(int height, int weight);
    
    system("CLEAR");
    
    cout << "Your body mass index is " << BMI <<;
    
    
    
    
    
    
    
    
    return 0
}



int convert(int foot, int inch) {
    int finalHeight = foot * 12 + inch * .0254;
    return finalHeight * finalHeight
}

int convertWeight(int pound) {
       return pound / 2.2;
}

int convertFinal(int weight, int height) {
    return weight / height;
}    
    
ObTsu
ObTsu
Well, before I post the error messages, yes, most of them are syntax errors. I'm sorry, I'm a noob, but I can't figure out what to do.
Boku San
Boku San
One error is in your usage of assigning variables to return types.

If you want height to equal the return value of x function, use height = function(params);

You placed return types, which the compiler probably saw as declaring new functions within...variables?

After you've declared a function's return type and parameters, you don't need to do it anymore. Although sometimes it would be helpful in thought processes for overloaded functions...
Things change.
ObTsu
ObTsu
I changed the code to say

height = convert(int foot, int inch);

rather than

height = int convert(int foot, int inch);



but it still gives me an error.
Boku San
Boku San
Quote:
Original post by ObTsu
I changed the code to say

height = convert(int foot, int inch);

rather than

height = int convert(int foot, int inch);



but it still gives me an error.


You don't need keywords in parameters either. Isn't C++ FRIENDLY? *twitch*

Here you go, this looks about right...I'll fix anything else I see wrong after I post it, mmkay?

#include <iostream>int convert(int foot, int inch);int convertWeight(int pound);int convertFinal(int weight, int height);using namespace std;    int foot;    int inch;    int pound;    int height;    int weight;    int BMI;    int finalBMI;    int finalHeight;    int finalWeight;int main() {      cout << "Input your height in feet\n";    cin >> foot;    cout << "Input your height in inches\n\n";    cin >> inch;    height = convert(foot, inch);     cout << "Input your weight in pounds\n";      cin >> pound;       weight = convertWeight(pound);       BMI = convertFinal(height, weight);    //    system("CLEAR");    cout << "Your body mass index is " << BMI << endl;    return 0;}int convert(int foot, int inch) {    int finalHeight = foot * 12 + inch * .0254;    return finalHeight * finalHeight;}int convertWeight(int pound) {       return pound / 2.2;}int convertFinal(int weight, int height) {    return weight / height;}    



EDIT: Okay, fixed on my compiler
Things change.
Boku San
Boku San
Quote:
Original post by Anonymous Poster
First off, when you call functions in the program, don't specify the return value, and don't specify the type of variable you are passing, so in the 4 line of code in the main function it should be:
*** Source Snippet Removed ***
As far as I know system("CLEAR") won't do anything. I don't know if you are using windows, but on windows, to clear the screen, as far as I know, you would use system("cls"). In the convert function you also forgot a semicolon after the return line. Hopefully thats everything and good luck!


AP's right. I commented out the system("CLEAR") and fixed syntax errors in above example.
Things change.
ObTsu
ObTsu
Thanks ALOT, boku. I'll be coming to GDNet alot more now. Well anyway, I don't feel like comparing the code right now, so could you tell me exactly what you did to make it work? Knowledge is what I need :p. Oh, and PS, I added a system("PAUSE") to the end of int main() :).
Boku San
Boku San
Quote:
Original post by ObTsu
Thanks ALOT, boku. I'll be coming to GDNet alot more now. Well anyway, I don't feel like comparing the code right now, so could you tell me exactly what you did to make it work? Knowledge is what I need :p. Oh, and PS, I added a system("PAUSE") to the end of int main() :).


Uhh...thanks? I was kinda disappointed in myself since I had to run it through a compiler to check for syntax, but w/e.

I think maybe you misunderstood the idea of overloading functions...maybe? Anyway, I've made the mistake before, you just get used to it.

I was gonna say a lot more, but I got to go to bed.
Things change.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.