Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Help with a float

  • 13-03-2007 8:05pm
    #1
    Closed Accounts Posts: 153 ✭✭


    I am currently making this in borland c++ but not sure what to do next....You ideas would be greatfull.....

    Basically i want it to work proberly....


    #include<iostream.h>
    #include<conio.h>
    void cont();
    float ctof(int,float*);
    float ftoc(int,float*);

    void main()

    {

    float a,temp[10];
    int x;

    cout<<"Please enter 10 temperatures Now"<<endl;

    for(x=1;x<11;x++)
    {
    cout<<"Temperature "<<x<<" :";
    cin>>a;


    a = temp[x];

    cout<<endl;

    }

    cont();

    getch();

    }
    //
    void cont()
    {

    int y=0;
    while(y<3)

    {
    clrscr();

    cout<<"Please enter the scale you wish to convert to"<<endl;
    cout<<"1)celcius"<<endl;
    cout<<"2)farenheit";
    cin>>y;

    if(y=1)
    float ftoc(int,float[10]);

    if(y=2)
    float ctof(int,float temp[10]);
    }
    }
    float ctof(int x,float temp[10])

    {

    int z;
    float cel,c;

    for(x=0;x<11;x++)
    {
    temp[x];
    cel = c/4;
    cout<<"temp in celcius ="<<cel<<endl;
    }
    }
    //
    float ftoc(int,float temp[10])
    {
    cout<<"hello"; //
    This part is just a test
    }


Comments

  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    What, not even a description of the problem or error before we dive into the code and have to dig it out ourselves? If you want to be helped, try helping us first...


  • Closed Accounts Posts: 153 ✭✭Bummer


    Sorry about that...It was abit rushed........There is no errors on it...it runs but the problems occur when It wants me to enter in the scale that i want to convert It won't enter for me.........


  • Registered Users, Registered Users 2 Posts: 228 ✭✭Mary-Ellen


    haven't programmed in C++ in a while and I do a few languages so hope I'm not just confused

    but in if statements in C++ shouldn't it be ==

    I think

    eg:
    (y = 1)
    assigns the value 1 to the variable name y

    (y == 1)
    checks if the value of y is 1

    hope that helps:rolleyes:


  • Closed Accounts Posts: 4,368 ✭✭✭thelordofcheese


    yeah thats about the only error i can see in it.


  • Registered Users, Registered Users 2 Posts: 2,013 ✭✭✭lynchie


    your for loop goes from 1 <11 instead of 0 < 10, so the last temp u enter is going to go into no man's land (temp[10]).. same again at the last loop when u go from 0<11 and try to reference temp[10] again.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 7,278 ✭✭✭kenmc


    Yeah the loop is totally off by 1. Arrays in C and C++ range from 0 to N-1
    for(x=1;x<11;x++)
    {
    cout<<"Temperature "<<x<<" :";
    cin>>a;
    a = temp[x]; <-- what is this supposed to do exactly? you've just read in 'a' and now you're overwriting it straight away.
    cout<<endl;
    }

    also....
    these 2 take a pointer to float as the last parameter
    float ctof(int,float*);
    float ftoc(int,float*);

    yet.....
    if(y=1)
    float ftoc(int,float[10]);
    if(y=2)
    float ctof(int,float temp[10]);

    these two pass a float, but are out of range of the array.


  • Registered Users, Registered Users 2 Posts: 5,112 ✭✭✭Blowfish


    Bummer wrote:
    Sorry about that...It was abit rushed........
    Also, just a suggestion, if you use the [noparse]
    
    [/noparse] tags when posting, it will keep the indentation and make it a lot easier for us to read :)                                            


  • Closed Accounts Posts: 89 ✭✭Colin Mac


    void main() is wrong. It should be int main.

    Also <iostream.h> is the depreciated way of including the header file.
    It should be written as just <iostream>, without the h.


  • Registered Users, Registered Users 2 Posts: 7,278 ✭✭✭kenmc


    Colin Mac wrote:
    void main() is wrong. It should be int main.

    Also <iostream.h> is the depreciated way of including the header file.
    It should be written as just <iostream>, without the h.

    Maybe so, but they are far far far down the list of issues currently with the code - they won't stop it working properly, whereas the logic mistakes will.


  • Closed Accounts Posts: 89 ✭✭Colin Mac


    kenmc wrote:
    Maybe so, but they are far far far down the list of issues currently with the code - they won't stop it working properly, whereas the logic mistakes will.

    And your point is what exactly - Should I not have mentioned it?

    void main, and iostream.h are all too common mistakes, and should be mentioned first and be done with, before talking logic. Seeing how they are the standards and need to be used correctly in every C++ program..


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 7,278 ✭✭✭kenmc


    My point was simply that these 2 are incredibly simple 1-second fixes, which can be done any time in the future. If the logic is not right it's a whole mindset that needs to be fixed/taught. <iostream.h> may be deprecated, but used work fine (that was the way it was when I first learned it, so the text books possibly have not been changed) and most probably still does. void main may throw a warning, but will still compile fine on most compilers. accessing a 10-element array at index 11 has never worked, and never will, in c++.
    What I'm trying to say is that there's no point in decorating the house if the roof is missing.


  • Closed Accounts Posts: 89 ✭✭Colin Mac


    >>10-element array at index 11 has never worked, and never will, in c++.

    Completely beside the point that
    a program should never be compiled with main and iostream declared incorrectly, whether it seems to work or not.

    >> My point was simply that these 2 are incredibly simple 1-second fixes,

    Exactly.


  • Closed Accounts Posts: 7,563 ✭✭✭leeroybrown


    Something else that might make the code above error with recent C++ compiler releases is the implicit use of the std namespace for cout, cin and endl. Some compilers would probably require that the std namespace was either explicitly referenced:
    std::cout << "Hello" << std::endl;
    

    or imported with the using keyword, either individually:
    using std::cout;
    using std::endl;
    

    or for the entire namespace (individual imports would typically be preferred):
    using namespace std;
    


Advertisement