# Problem with function

• 09-27-2011
iGuardian
Problem with function
Question regarding the response issue. I am having the user input 1 in order to calculate for meters/centimeters and 2 for inches and feet. It has to be an if/else statement, but whenever I run it, it continues onto the next calculation without selecting a choice. Any suggestions would be appreciated
Code:

```#include <iostream> using namespace std; void get_input ( double inches, double feet ); void give_output( double centimeters, double meters ); int main () {     double inches, feet, meters, centimeters;     char response = '1' || '2';     cout << "We are going to convert inches and feet into meters." << endl;     cout << "Please input the measurement output you would like.";     cout << "(1 for meter and centimeter  output, 2 for inches and feet output)";     cin >> response;     cout << endl;     if ( response = 1 ) {         void get_input ( double inches, double feet );         {         cout << "Please input the feet measurement: ";         cin >> feet;         cout << endl;         cout << "Please input the inches measurement: ";         cin >> inches;         cout << endl;         }     feet = inches * 12;     meters = feet * 0.3048;     centimeters = meters * 100;     inches = feet / 12;         void give_output( double centimeters, double meters );         {         cout << " There are ";         cout << meters;         cout << " meters from the given measurements." << endl;         cout << " There are ";         cout << centimeters;         cout << " centimeters from the given measurements." << endl;         }     }     else ( response = 2 ); {     void get_input ( double meters, double centimeters );         {         cout << "Please input the meters measurement: ";         cin >> meters;         cout << endl;         cout << "Please input the centimeters measurement: ";         cin >> centimeters;         cout << endl;         }         void give_output( double feet, double inches );         {         cout << " There are ";         cout << feet;         cout << " feet from the given measurements." << endl;         cout << " There are ";         cout << inches;         cout << " inches from the given measurements." << endl;         }     } }```
• 09-28-2011
AndrewHunter
Quote:

Code:

``` char response = '1' || '2'; //what do you think this does?```
Code:

``` if ( response = 1 ) { //this is the assignment operator. You need if(response ==1)```

Additionally, since you define response as a char (not sure why you would do that) that evaluation is always false. You really need to sit down and re-read your textbook. You are missing some serious knowledge here.
• 09-28-2011
Elysia
I am thinking you need to read some basic tutorials on if statements and functions.
• 09-28-2011
iGuardian
Code:

`#include <iostream>using namespace std;void get_input ( double &inches, double &feet );void give_output( double centimeters, double meters );int main (){    double inches, feet, meters, centimeters;    char response = '1' || '2' ;    char answer = 'y';    cout << "We are going to convert inches and feet into meters." << endl;    cout << "Please input the measurement output you would like." << endl;    cout << "(1 for meter and centimeter output, 2 for inches and feet output): ";    cin >> response;    cout << endl;    if ( response == '1' ) {        get_input ( inches, feet );    feet = inches * 12;    meters = feet * 0.3048;    centimeters = meters * 100;        give_output ( centimeters, meters );        cout << " Would you like to re-use this program ( Y - yes, N - no ): ";        cin >> answer;    }    else if ( response == '2' ) {    void get_input ( double meters, double centimeters );        {        cout << "Please input the meters measurement: ";        cin >> meters;        cout << endl;        cout << "Please input the centimeters measurement: ";        cin >> centimeters;        cout << endl;        }    inches = feet * 12;    feet = meters * 39.37;    meters = centimeters / 100;        void give_output( double inches, double feet );        {        cout << " There are ";        cout << feet;        cout << " feet from the given measurements." << endl;        cout << " There are ";        cout << inches;        cout << " inches from the given measurements." << endl;        }        cout << " Would you like to re-use this program ( Y - yes, N - no ): ";        cin >> answer;    }}void get_input ( double &inches, double &feet ){        cout << "Please input the feet measurement: ";        cin >> feet;        cout << endl;        cout << "Please input the inches measurement: ";        cin >> inches;        cout << endl;}void give_output( double centimeters, double meters ){        cout << " There are ";        cout << meters;        cout << " meters from the given measurements." << endl;        cout << " There are ";        cout << centimeters;        cout << " centimeters from the given measurements." << endl;}`
Is this on the right track?
• 09-29-2011
AndrewHunter
Yes, you are on the right track. Lines 8 and 9 only need to declare the variable; specifically line 8 doesn't really do anything useful. Your program doesn't actually loop; take a look at Lesson 3:Loops. Additionally, you still haven't wrapped your head around functions yet - do not define them in main. Read Lesson 4:Functions.