• Register
1 vote
17 views

Problem:

I am trying to make a program that will convert the temperature from Celcius to Fahrenheit and vice-versa.

The sample code is attached below:

#include <iostream>

using namespace std;

void dialouge();
int c2f();
int f2c();

int c2f()
{
    int c;
    int choice;
    cout << "Please enter the degree in Celsius: \n";
    cout << ":.: ";
    cin >> c;
    cout << ":F: " << c * 1.8 + 32 << endl;
    cin.get();

    cout << "Convert another degree?\n";
    cout << "1. Yes.\n";
    cout << "2. No.\n";
    cout << ":.: ";
    cin >> choice;

    if (choice == 1)
    {
        dialouge();
    }

    else if (choice == 2)
    {
        return 0;
    }
}

int f2c()
{
    int f;
    int choice;
    cout << "Please enter the degree in Fahrenheit: \n";
    cout << ":.: ";
    cin >> f;
    cout << ":C: " << f - 32 * 5 / 9 << endl;
    cin.get();

    cout << "Convert another degree?\n";
    cout << "1. Yes.\n";
    cout << "2. No.\n";
    cout << ":.: ";
    cin >> choice;

    if (choice == 1)
    {
        dialouge();
    }

    else if (choice == 2)
    {
        return 0;
    }
}

void dialouge()
{
    int choice;
    cout << "Please choose your desired option:-\n";
    cout << "1. Celsius to Fahrenhite.\n";
    cout << "2. Fahrenhite to Celsius.\n";
    cout << ":.: ";
    cin >> choice;

    if (choice == 1)
    {
        c2f();
    }

    else if (choice == 2)
    {
        f2c();
    }
}

int main()
{
    cout << "This program allows you to convert from Celsius to Fahrenheit and vice versa.\n";
    dialouge();

}

 

But the problem is: When I compile it, CodeBlocks keeps giving me the following warning:
int f2c(): control reaches end of non-void function
int c2f(): control reaches end of non-void function

what does it mean? and if there is anything wrong that I haven't noticed, please point it out.

12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

1 vote

Solution:

The compiler throws back the error because the functions f2c and c2f do not return values on all control paths.

I hope this will help you:

int func(int choice) // This function will return an integer value
{
    if(choice == 1)
    {
        return 1;  // If choice is not 1, then this code is never executed and the function will not return an int
    }
}

int func2(int choice)
{
    if(choice == 1)
    {
        return 1;  // If choice is 1, then 1 is returned
    }
    return 0;  //If choice is not 1, then 0 is returned, so every possible control path returns something
}

Thanks

13 9 6
94,240 points

Related questions

0 votes
1 answer 3 views
3 views
Problem: I run the following C codes and got a warning: control reaches end of non-void function int main(void) {}what does it mean? and if there is anything wrong that I havent noticed, please point it out
asked Dec 21, 2020 Mashhoodch 5.6k points
0 votes
1 answer 5 views
5 views
Problem: I've been getting strange compiler errors on this binary search algorithm. I get a warning that control reaches end of non-void function. What does this mean?
asked Dec 15, 2020 Mashhoodch 5.6k points
0 votes
1 answer 30 views
30 views
Problem: I have recently started learning C language as currently lockdown is going on so I am learning C language with the help of available online tutorials. I have managed to write the binary search algorithm. If I try to compile my binary search algorithm then I am facing very ... +1, high);     else if(val == sorted[mid])         return mid; } Please guide me in fixing my above C code.
asked Aug 1, 2020 Raphael Pacheco 4.9k points
1 vote
1 answer 166 views
166 views
Problem : I am learning C. If I try to compile my below code then I often face an error message as shown below &ldquo;Warning: control may reach end of non-void function [-wreturn-type]&rdquo;. How can I fix my below code to avoid above error message? Below is my code which is ... (board[r][c - 1] == 0)         {             return true;         }     }     else     {         return false;     } }
asked Apr 27, 2020 stewart 4k points
0 votes
1 answer 4 views
4 views
Problem: I've been working on some C++ code that a friend has written and I get the following error that I have never seen before when compiling with gcc4.6: Edit: This comes from a part of the code using boost MSM: Boost Webpage Edit2: There is no = delete() used anywhere in the sourcecode. Generally speaking, what does this error mean? What should I be looking for when this type of error occurs?
asked Dec 24, 2020 Mashhoodch 5.6k points
0 votes
1 answer 11 views
0 votes
1 answer 42 views
42 views
I am new to python programming language. I wrote a where I tried to pass a list of functions : def function(f. *args) for f in args print f I can not pass my list of function using this code It gives me error File "main.py", line 1 def function(f. *args) ^ ... : File "main.py", line 1 def function(*args) ^ SyntaxError: invalid syntax How can I solve this and how can I pass a list of function?
asked Mar 12, 2020 LizzyM 6.1k points
1 vote
1 answer 35 views
35 views
Problem: I am exploring the c++ programming language nowadays. It&rsquo;s really interesting to learn new things every day. I was trying to adopt the methods in c++ but struggling to return values from a void method. I actually want to know that if it is ... a return statement in a void method. Thanks for your co-operation in this learning process. I really appreciate your effort. Thanks again.
asked Mar 25, 2020 Gavin 15.3k points
0 votes
1 answer 74 views
74 views
Problem: I have written the following class: class Foo { private:     static float scale; public:     static float setScale(float scale); }; If I try to implement the setScale() function as shown below: float Foo::setScale(float scale) {    this->scale = ... still throws the same error. Now I am really confused about the above error message as my function in question is already marked as static.
asked Aug 13, 2020 Raphael Pacheco 4.9k points
2 votes
1 answer 133 views
133 views
Problem: Hello guys, I am taking an Udemy online course in C++ recently. I joined a few days back and learning the language step by step. Today, I found a problem in my c++ code that&rsquo;s stopping my code running. My program is giving back an error &ldquo;Invalid use ... main.cpp: In function int main()': main.cpp:13:31: error: invalid use of void expression int n = function2(function1()); ^
asked Apr 19, 2020 Gavin 15.3k points