Thread: Ok take a look at this program

  1. #1
    I'm less than sure.... abyssphobia's Avatar
    Join Date
    Aug 2004
    Posts
    112

    Ok take a look at this program

    whats your opinion ??? please run it !!!! to see what it does.

    # include <iostream.h>
    # include <stdlib.h>


    double on,lb,gramo,kilo,gina,total;



    void main()

    {
    char no;
    do{
    cout <<" \n Put Ur Weight In thE sYsteM EnglIsH ";
    cout<<"\n ";
    cout<<"\n libras: ";
    cin>>lb;
    cout<<" onzas: ";
    cin>>on;

    kilo= lb/ 2.2046;
    gramo= on/.0352736;
    gina = gramo/1000;
    total = kilo+gina;

    cout<<"\ntu el peso en kilos es "<<kilo;
    cout<<"\nY en gramos es "<<gramo;
    cout<<"\n\n Pero en Total Tu peso es "<<total;
    cout<<" \n\n deseea otra operacion??s/n ";
    cin>>no;
    cout<<"\n";

    }while(no!='n');
    }

  2. #2
    I'm less than sure.... abyssphobia's Avatar
    Join Date
    Aug 2004
    Posts
    112
    if u found a improvement please send it , I be glad to see. it was mi final exam , so easy as you see.


    Quote Originally Posted by abyssphobia
    whats your opinion ??? please run it !!!! to see what it does.

    # include <iostream.h>
    # include <stdlib.h>


    double on,lb,gramo,kilo,gina,total;



    void main()

    {
    char no;
    do{
    cout <<" \n Put Ur Weight In thE sYsteM EnglIsH ";
    cout<<"\n ";
    cout<<"\n libras: ";
    cin>>lb;
    cout<<" onzas: ";
    cin>>on;

    kilo= lb/ 2.2046;
    gramo= on/.0352736;
    gina = gramo/1000;
    total = kilo+gina;

    cout<<"\ntu el peso en kilos es "<<kilo;
    cout<<"\nY en gramos es "<<gramo;
    cout<<"\n\n Pero en Total Tu peso es "<<total;
    cout<<" \n\n deseea otra operacion??s/n ";
    cin>>no;
    cout<<"\n";

    }while(no!='n');
    }

  3. #3
    Registered User
    Join Date
    Jul 2004
    Posts
    101
    >># include <iostream.h>
    >># include <stdlib.h>
    Neither of these are legal C++ anymore. They may work on modern compilers and will work on older compilers, but keep in mind that you are working with pre-standard C++.

    >>double on,lb,gramo,kilo,gina,total;
    There is no reason to use global variables when the only function in your program is main.

    >>void main()
    This has never been correct. main returns an integer.

    Here is the same code modernized, corrected, and with consistent formatting.
    Code:
    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    
    int main() 
    {
      double on, lb, gramo, kilo, gina, total;
      char no;
    
      do{
        cout << " \n Put Ur Weight In thE sYsteM EnglIsH ";
        cout << "\n "; 
        cout << "\n libras: ";
        cin >> lb;
        cout << " onzas: ";
        cin >> on;
    
        kilo = lb / 2.2046;
        gramo = on / .0352736;
        gina = gramo / 1000;
        total = kilo + gina;
    
        cout << "\ntu el peso en kilos es " << kilo;
        cout << "\nY en gramos es " << gramo;
        cout << "\n\n Pero en Total Tu peso es " << total;
        cout << " \n\n deseea otra operacion??s/n "; 
        cin >> no;
        cout << "\n";
      }while (no != 'n');
    
      return 0;
    }

  4. #4
    I'm less than sure.... abyssphobia's Avatar
    Join Date
    Aug 2004
    Posts
    112
    Thx,well Im using a older compiler,Princeton Thx a lot, Ill take in mind. =)

  5. #5
    I'm less than sure.... abyssphobia's Avatar
    Join Date
    Aug 2004
    Posts
    112
    Ok I ran the code like u put princeton, and it works, ok its not a compilers issue , it the way my teacher theach me;So thank you so much. Now I know a better way to use that, Cuz Im a begginer as you see.

  6. #6
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    no offense, but i'm kindof surprised your teacher is teaching you global variables this early on. there is always a way around using them, except for very very rare cases. i've seen teachers teach void main, as though it should, i see some of their points in doing so in the beginning..

  7. #7
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  8. #8
    I'm less than sure.... abyssphobia's Avatar
    Join Date
    Aug 2004
    Posts
    112

    Red face Hi Im almost out of this bbs, Im hungry

    Well Thx a lot,
    Ive learn so much. The code that I posted makes your weight to lb trought kilogram, well just in case you want to know mmm it was my final test, It was a pleasure , this time , I read a lot of the post make today, but I feel like I need more time to try to help another people, I will try. Thank you to everyone
    love,
    abyssphobia
    the dark side girl
    Have I crossed the line?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM