Ask Experts Questions for FREE Help !
Ask
    Harris2007's Avatar
    Harris2007 Posts: 1, Reputation: 1
    New Member
     
    #1

    Sep 23, 2007, 07:37 AM
    C++ programming Qs (beginner)
    Hi there... I am a novice in C++ programming. I wrote a very simple 'temperature conversion' program that asks user to input whether they want a Celsius to Fahrenheit conversion, or the opposite, and then calls the respective function (i.e. either a Celsius to Fahrenheit converter OR a Fahrenheit to Celsius converter). When I run the program, only the first function (i.e. C to F conversion) runs. Can you please let me know what I'm doing wrong? The code is as follows. Thanks for your help!!

    # include <iostream>
    # include <cmath>
    void cfconverter (double);
    void fcconverter (double);

    int main ()
    {
    using namespace std;
    double t;
    int decide;
    cout<<"Temperature Converter\n\n";
    cout<<"Do you want C-to-F [1] OR F-to-C [2] conversion? Enter '1' or '2'";
    cin>>decide;
    cout<<"Enter temperature: ";
    cin>>t;
    if (decide=1) {cfconverter(t);}
    else {fcconverter(t);}
    return 0;
    }

    void cfconverter (double t)
    {
    using namespace std;
    double f;
    f=(1.8*t)+32;
    cout<<"\nA temperature of "<<t<<" in Celsius = "<<f<<" in Fahrenheit\n";
    }

    void fcconverter (double t)
    {
    using namespace std;
    double c;
    c=(t-32)/1.8;
    cout<<"\nA temperature of "<<t<<" in Fahrenheit = "<<c<<" in Celsius\n";
    }
    asterisk_man's Avatar
    asterisk_man Posts: 476, Reputation: 32
    Full Member
     
    #2

    Sep 23, 2007, 12:10 PM
    common problem :)

    should be

    (decide==1) instead of (decide=1)

    = is assignment, == is comparison

    hope this helps!

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

A beginner in Sales [ 5 Answers ]

Hello, I am new to this website and I am very new to sales. My fiance's aunt created her own mineral-based makeup line called about face by Pamela John. I have recently started to find retail stores such as salons and boutiques to carry her line. I was wondering what your thoughts were on...

Beginner in computer field [ 2 Answers ]

I am a new fellow in the field of computers. Please tell me about the basics of computer management, how it works and how to become an expert in this field

Computer building beginner. [ 4 Answers ]

I'm planning on building a new computer for class, but I've never built one before. I'm going to get a lot of help along the way, but I need some feedback on the hardware and the potential compatibility issues before I make the purchase. It has to be under 800 USD. So here you go. Antec...

Computer beginner [ 1 Answers ]

I'm new to computers and I just got a notebook, there was really no actual manual with it, just basic information, my question is what are the top row of keys, the ones that have f1-f2, etc, what are they for and how do you use them, not only are they label fi, but it also has a question mark...


View more questions Search