Code will not compile

l
Last edited on
Please use code tags. http://www.cplusplus.com/articles/jEywvCM9/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
    do{
        menu();
        
        switch (choice)
        case 1:
            cout << "enter meters: ";
            cin >> m;
            cout << "feet" << Meters_to_Feet(m, .3048) << endl;
            while (choice = 1)
                break;
        case 2:
            cout << "enter feet";
            cin >> f;
            cout << "meters" << feet_to_meters(f, .3048) << endl;
            while (choice = 2)
                break;
        case 3:
            cout << "enter length in meters";
            cin >> l;
            cout << "enter width in meters";
            cin >> w;
            cout << "square feet" << Length_Width_Feet(l, w, .3048) << endl;
           while (choice = 3)
                break;
        case 4:
            cout << "enter length in feet";
            cin >> l;
            cout << "enter width in feet";
            cin >> w;
            cout << "square meters" << Length_Width_Meters(l, w, .3048) << endl;
            while (choice = 4)
                break;
        case 5:
            while (choice = 5)
                break;
        default:
            cout << "please select (1-5) only" << endl;

        } while (choice = !5);

I've bolded and underlined your mistakes in this code. You're also missing curly braces for the switch statement.
What's the mistake?
 
while (choice = 1)

It's two equal signs (==) for equality.
I don't know what your purpose is for putting this while loop in every case.

 
while (choice = !5);

meant to be while (choice != 5);
okay I was wondering that
But what about the last part? It tells me not to use curly braces and then when I don't it tells me to
But what about the last part? It tells me not to use curly braces and then when I don't it tells me to

Be more specific. Where is the last part? What is "it" referring to?
I'm refering to this part

void menu()
{
cout << "English Metric Junior" << endl;
cout << "1) convert from meters to feet" << endl;
cout << "2) convert from feet to meters" << endl;
cout << "3) compute the area of a rectangle in sqaure feet given length and width in meters" << endl;
cout << "4) compute the area of a rectangle in sqaure meters given length and width in feet" << endl;
cout << "5) quit the program" << endl;
cout <<" Please enter a number (1-5) -> "
}

\\ primarily down here

double Meters_to_Feet(double m, double f)
{
return m*f;
}

double feet_to_meters(double f, double m)
{
return f / m;
}
double Length_Width_Feet(double l, double w, double f)
{
return l*w*f;
}
double Length_Width_Meters(double l, double w, double m)
{
return l*w/m;
}
Please use code tags. http://www.cplusplus.com/articles/jEywvCM9/

Seems fine to me.

Have you fixed the aforementioned mistakes?
This is what it looks like now



#include <iostream>
#include <cmath>
using namespace std;

void menu();
double Meters_to_Feet(double m,double f);
double feet_to_meters(double f,double m);
double Length_Width_Feet(double l, double w, double m);
double Length_Width_Meters(double l, double w, double f);


int main(){

double f, m, l, w;
int choice;
cin >> choice;
do
{
menu();
switch (choice)
{
case 1:
cout << "enter meters: ";
cin >> m;
cout << "feet" << Meters_to_Feet(m,.3048) <<endl;
break;
case 2:
cout << "enter feet";
cin >> f;
cout << "meters" << feet_to_meters(f,.3048) <<endl;
break;
case 3:
cout << "enter length in meters";
cin >> l;
cout << "enter width in meters";
cin >> w;
cout << "square feet" << Length_Width_Feet(l,w,.3048) <<endl;
break;
case 4:
cout << "enter length in feet";
cin >> l;
cout << "enter width in feet";
cin >> w;
cout << "square meters" << Length_Width_Meters(l,w,.3048)<< endl;
break;
case 5:
break;
default:
cout << "please select (1-5) only" <<endl;
}while (choice =! 5);

return 0;

void menu();

cout << "English Metric Junior" << endl;
cout << "1) convert from meters to feet" << endl;
cout << "2) convert from feet to meters" << endl;
cout << "3) compute the area of a rectangle in sqaure feet given length and width in meters" << endl;
cout << "4) compute the area of a rectangle in sqaure meters given length and width in feet" << endl;
cout << "5) quit the program" << endl;
cout <<" Please enter a number (1-5) -> ";


double Meters_to_Feet(double m, double f)
{
return (m * f);
}

double feet_to_meters(double f, double m)
{
return (f / m);
}

double Length_Width_Feet(double l, double w, double f)
{
return (l * w * f);
}

double Length_Width_Meters(double l, double w, double m)
{
return (l * w / m);
}

Please use code tags. http://www.cplusplus.com/articles/jEywvCM9/

1
2
3
4
5
6
7
8
9
10

void menu();

cout << "English Metric Junior" << endl;
cout << "1) convert from meters to feet" << endl;
cout << "2) convert from feet to meters" << endl;
cout << "3) compute the area of a rectangle in sqaure feet given length and width in meters" << endl;
cout << "4) compute the area of a rectangle in sqaure meters given length and width in feet" << endl;
cout << "5) quit the program" << endl;
cout <<" Please enter a number (1-5) -> ";

You had this section correct in your previous post. What happened?

Instead of this
1
2
3
4
double Meters_to_Feet(double m, double f)
{
    return (m * f);
}

why not do this
1
2
3
4
double Meters_to_Feet(double m)
{
    return (m * 0.3048);
}

No point passing 0.3048 as an argument if it's a constant.
okay I got every thing work except one little spot


#include <iostream>
using namespace std;

void menu();
double Meters_to_Feet(double m,double f);
double Feet_To_Meters(double f,double m);
double Length_Width_Feet(double l, double w, double m);
double Length_Width_Meters(double l, double w, double f);

int main()
{
double f, m, l, w;
int choice;
do
{
menu();
cin >> choice;
switch (choice)
{
case 1:
cout << "enter meters";
cin >> m;
cout << "feet" << Meters_to_Feet(m,.3048) <<endl;
break;
case 2:
cout << "enter feet ";
cin >> f;
cout << "meters" << Feet_To_Meters(f,.3048) <<endl; \\ right here
break;
case 3:
cout << "enter length in meters";
cin >> l;
cout << "enter width in meters";
cin >> w;
cout << "sqaure feet " << Length_Width_Feet(l,w,.3048) <<endl;
break;
case 4:
cout << "Enter length in feet";
cin >> l;
cout << "enter width in feet";
cin >> w;
cout << "square meters" << Length_Width_Meters(l,w,.3048) <<endl;
break;
case 5:
break;
default:
cout << "Invalid input" << endl;
}
}while (choice != 5);

return 0;
}

void menu()
{
cout << "English Metric Junior" << endl;
cout << "1) convert from meters to feet" << endl;
cout << "2) convert from feet to meters" << endl;
cout << "3) compute the area of a rectangle in square feet given length and width in meters" << endl;
cout << "4) compute the area of a rectangle in square meters given the length and width in feet" << endl;
cout << "5) quit the program" << endl;
cout << "Please enter a number (1-5) ->";
}

double Meters_to_Feet(double m,double f)
{
return m * .3048;
}

double feet_to_meters(double f, float m)
{
return f / .3048;
}

double Length_Width_Feet(double l, double w, double m)
{
return l * w * .3048;
}

double Length_Width_Meters(double l, double w, double f)
{
return l * w / .3048;
}
Last edited on
Here we go: 4th time lucky.
Please use code tags. http://www.cplusplus.com/articles/jEywvCM9/
You can edit your posts, highlight your code and click the <> button on the right.

okay I got every thing work except one little spot

Care to explain?
It says undefined reference to Feet_To_Meters
Please use code tags. http://www.cplusplus.com/articles/jEywvCM9/
You can edit your posts, highlight your code and click the <> button on the right.

C++ is case sensitive.
Your declaration:
 
double Meters_to_Feet(double m,double f);

Your definition:
1
2
3
4
double feet_to_meters(double f, float m)
{
    return f / .3048;
}


Please use code tags. http://www.cplusplus.com/articles/jEywvCM9/
You can edit your posts, highlight your code and click the <> button on the right.
line 28 is what I'm having a problem with

cout << "meters" << Feet_To_Meters(f,.3048) <<endl;
Thank you for sticking around and helping me. I feel like a dick sending you all those walls of text even though you kept sending me that link
Last edited on
No worries. Just make sure you use code tags in the future.
Have a great day! :)
Topic archived. No new replies allowed.