• Register
1 vote
30 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 2 views
2 views
Problem : Why a warning of "control reaches end of non-void function" for the main function?
asked 6 days ago padma1 22.4k points
0 votes
1 answer 11 views
11 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 13k points
0 votes
1 answer 1 view
1 view
Problem: How to solve the issue>control reaches end of non void function
asked 12 hours ago ashik 12.7k points
0 votes
1 answer 1 view
1 view
Problem: How to get the correct solution of this:control reaches end of non-void function
asked 17 hours ago ashik 12.7k points
0 votes
1 answer 2 views
2 views
Problem: I am stuck with this error: control reaches end of non-void function.Please help me that how to deal with this error?
asked Mar 27 ashik 12.7k points
0 votes
1 answer 4 views
4 views
Problem: I got some error. error: control reaches end of non-void function [-werror=return-type],please someone help me to fix this.
asked Mar 27 ashik 12.7k points
0 votes
1 answer 2 views
2 views
Question: I run the following C codes and got a warning: control reaches end of non-void function int main(void) {} Any suggestions?
asked 6 days ago Atik03 10.1k points
0 votes
1 answer 6 views
6 views
Problem: Why a warning of &ldquo;control reaches the end of non-void function&rdquo; for the main function? Any suggestions?
asked Mar 15 ummesalma 25.2k points
0 votes
1 answer 15 views
15 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 13k points
0 votes
1 answer 40 views
40 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