Ok, final project!

Pages: 12
I am so sorry that i have been asking to many questions these days...
After all the input, here's the last thing to do on my project that i got lost completely.

I have to produce a program that use the function call technique to combine two things using if else statement. The program consist of:
1) English to metric system conversion
2) metric to English system conversion

The user will input symbol 1 or 2 to determine the program to execute either program 1) or program 2).
How do i do that?

I plug all things that i did so far, but, still can't pass through the compiler with the if-else statement. Can someone help me to point out my mistake and give me some better ideas on how to do/improve this please?

NB: Please ignore the repetition usage of the using namespace std; please. The book told me to do so! (it's Savitch c++).

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

void intro();
void introduction();

void get_value(int& value1);
void get_numbers(int& input1, int& input2);

double do_math(int meter);
double conversion(int feet, int inches);

void print_results(int output1, int output2);
void show_results(int results1, double results2);

int main(){

int m, f, i;
double final_pounds, final_inches, pounds_convert, final_meter, final_cm, end_meter;
const int inch = 12, meter = 100;
char symbol;

cout<<"Welcome!Enter 1 to proceed to a metric system to English system conversion or enter 2 to proceed to an English system to metric system conversion."<<endl;
cin>>symbol;

if (symbol == 1)

do{
intro();
get_value(m);
pounds_convert = do_math(m);

final_pounds =(pounds_convert);
final_inches =(pounds_convert - (floor(final_pounds)))*inch;
print_results(final_pounds, final_inches);
}


else (symbol == 2);
do{
introduction();
get_numbers(f,i);
end_meter = conversion(f,i);

final_meter =(end_meter);
final_cm =(end_meter - (floor(final_meter)))*meter;
show_results(final_meter, final_cm);
}

return (0);
}

void intro()
{
using namespace std;
cout<<"Welcome! This program converts the metric sytems units to English system units."<<endl;
}

void get_value(int& value1 )
{
using namespace std;
cout<<"Enter the number of meter in integers: "<<endl;
cin>>value1;
}

double do_math(int meter)
{
using namespace std;

double pounds_convert;
double const foot = 0.3048;

pounds_convert = meter/foot;

return pounds_convert;
}

void print_results(int output1, int output2)
{
using namespace std;

cout<<"The value in metric systems are "<<output1<< " lb and "<<output2<< " inch "<<endl;

return;

}

void introduction()
{
using namespace std;
cout<<"Welcome! This program converts the English sytems units to metric system units."<<endl;
}

void get_numbers(int& input1, int& input2)
{
using namespace std;
cout<<"Enter the number of feet and inches integers separately: "<<endl;
cin>>input1;
cin>>input2;
}

double conversion(int feet, int inches)
{
using namespace std;

double total_meter, end_meter;
double const foot = 0.3048, inch = 12;

total_meter = feet+(inches/inch);
end_meter = total_meter*foot;

return end_meter;
}

void show_results(int results1, double results2)
{
using namespace std;

cout<<"The value in metric systems are "<<results1<< " m and "<<results2<< "cm"<<endl;

return;

}
There is no "do" statement in C++. There is a "do-while" statement, but I don't think that's what you want. Try your program without the "do" statements; I don't think you need to replace them with anything.
OMG! U'RE AWESOME, IT WORKS!!! THANK YOU SO MUCH!
Heh...glad to help.
Well, ..... actually, i need to place to repeat request somewhere in the loop.
I've tried place it everywhere up in the main, but it didn't work. Now, i'm placing under the showresults function call, but it cannot execute for a new calculation when i enter Y. Why is that? where should i place it?

void show_results(int results1, double results2)
{
using namespace std;
char action;

cout<<"The value in metric systems are "<<results1<< " m and "<<results2<< "cm"<<endl;

do{
cout<<"Do you want to repeat a new calculation? [Y/y/N/n]"<<endl;
action = toupper (action);
cin>>action;
} while (action == 'y');

return;
}
Because:

while (action == 'y');

Doesn't test for uppercase "Y".

In the future, please put your code in tags, as I've done above. It makes it easier to read, and you're more likely to get responses.
And how do put the tags?
To the right of the box you put your reply in, there's a bunch of formatting icons. One looks like "<>" Press that, and put your code in the middle of what appears.
Here's my final code that has a problem with the REPEAT LOOP.
It doesn't work. I need it to execute back to the very beginning (where i have to choose to input symbol 1 or 2) for every time it ask for a repeat calculation.

Please have a look, on where i should have use it.
Oh, i used toupper, so it doesn't matter for either upper case or lower case letter.

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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include <iostream>
#include <cmath>
using namespace std;

void intro();
void introduction();

void get_value(int& value1);
void get_numbers(int& input1, int& input2);

double do_math(int meter);
double conversion(int feet, int inches);

void print_results(int output1, int output2);
void show_results(int results1, double results2);

int main(){

  int m; 
  double final_pounds, final_inches, pounds_convert;
  const int inch = 12;
  int choice;

  do{
  cout<<"Welcome!Enter 1 to proceed to a metric system to English system conversion or enter 2 to proceed to an English system to metric system conversion."<<endl;
  cin>>choice;
  
  if (choice == 1){
  intro();
  get_value(m);
  pounds_convert = do_math(m);

  final_pounds =(pounds_convert);
  final_inches =(pounds_convert - (floor(final_pounds)))*inch;
  print_results(final_pounds, final_inches);
    }

  else (choice == 2);
{ 

  int f, i;
  double final_meter, final_cm, end_meter;
  const int meter = 100;

  introduction();
  get_numbers(f,i);
  end_meter = conversion(f,i);

  final_meter =(end_meter);
  final_cm =(end_meter - (floor(final_meter)))*meter;
  show_results(final_meter, final_cm);
    }
   
} while (choice != 3);

    return (0);
}

void intro()
{
  using namespace std;
  cout<<"Welcome! This program converts the metric sytems units to English system units."<<endl;
}

void get_value(int& value1 )
{
  using namespace std;
 cout<<"Enter the number of meter in integers: "<<endl;
 cin>>value1;
}

double do_math(int meter)
{ 
  using namespace std;

  double pounds_convert;
  double const foot = 0.3048;

  pounds_convert = meter/foot;

  return pounds_convert;
}

void print_results(int output1, int output2)
{
  using namespace std;
  char action;

  cout<<"The value in metric systems are "<<output1<< " lb and "<<output2<< " inch "<<endl;
 
 do{
  cout<<"Do you want to repeat a new calculation? [Y/y/N/n]"<<endl;
  action = toupper (action);
  cin>>action;
 } while (action == 'n'); 

 return;

} 

void introduction()
{
  using namespace std;
  cout<<"Welcome! This program converts the English sytems units to metric system units."<<endl;
}

void get_numbers(int& input1, int& input2)
{
  using namespace std;
 cout<<"Enter the number of feet and inches integers separately: "<<endl;
 cin>>input1;
 cin>>input2;
}

double conversion(int feet, int inches)
{ 
  using namespace std;

  double total_meter, end_meter;
  double const foot = 0.3048, inch = 12;

  total_meter = feet+(inches/inch);
  end_meter = total_meter*foot;

  return end_meter;
}

void show_results(int results1, double results2)
{
  using namespace std;
  char action;

  cout<<"The value in metric systems are "<<results1<< " m and "<<results2<< "cm"<<endl;

 do{
  cout<<"Do you want to repeat a new calculation? [Y/y/N/n]"<<endl;
  action = toupper (action);
  cin>>action;
 } while (action == 'n'); 

 return;

} 
The tags are [code][/code].

Hope this helps :)
OK, I have to leave now, but...you have some uninitialized variables, and your processing of the choice logic isn't comprehensive. (What if choice = 4?) And you're still not testing your y/n correctly.

I'll check in later to see how you're doing with this.
but, that is my question... i don't know where i am supposed to place the repeat loop...

about choice 4. i put } while (choice < 2);
Not in the code you posted above, you didn't. Besides, do you really want to continue only if choice is less than 2? That will only work for a value of 1 or less.

I also noticed that you're casting your user's answer to uppercase BEFORE you read it. That's not going to do much for you.
Last edited on
Nope, i changed it.

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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include <iostream>
#include <cmath>
using namespace std;

void intro();
void introduction();
void get_value(int& value1);
void get_numbers(int& input1, int& input2);
double do_math(int meter);
double conversion(int feet, int inches);
void print_results(int output1, int output2);
void show_results(int results1, double results2);

int main(){

  int m; 
  double final_pounds, final_inches, pounds_convert;
  const int inch = 12;
  int choice = 2;

  do{
  cout<<"Welcome! Enter 1 to proceed to a metric system to English system conversion or enter 2 to proceed to an English system to metric system conversion."<<endl;
  cin>>choice;
  
  if (choice == 1){
  intro();
  get_value(m);
  pounds_convert = do_math(m);

  final_pounds =(pounds_convert);
  final_inches =(pounds_convert - (floor(final_pounds)))*inch;
  print_results(final_pounds, final_inches);
    }

  else (choice == 2);
{ 

  int f, i;
  double final_meter, final_cm, end_meter;
  const int meter = 100;

  introduction();
  get_numbers(f,i);
  end_meter = conversion(f,i);

  final_meter =(end_meter);
  final_cm =(end_meter - (floor(final_meter)))*meter;
  show_results(final_meter, final_cm);
    }
   
} while (choice <= 2);

    return (0);
}

void intro()
{
  using namespace std;
  cout<<"Welcome! This program converts the metric sytems units to English system units."<<endl;
}

void get_value(int& value1 )
{
  using namespace std;
 cout<<"Enter the number of meter in integers: "<<endl;
 cin>>value1;
}

double do_math(int meter)
{ 
  using namespace std;

  double pounds_convert;
  double const foot = 0.3048;

  pounds_convert = meter/foot;

  return pounds_convert;
}

void print_results(int output1, int output2)
{
  using namespace std;
  char action;

  cout<<"The value in metric systems are "<<output1<< " lb and "<<output2<< " inch "<<endl;
 
 do{
  cout<<"Do you want to repeat a new calculation? [Y/y/N/n]"<<endl;
  cin>>action;  
action = toupper (action);
 } while (action == 'y' || action != 'n'); 

 return;

} 

void introduction()
{
  using namespace std;
  cout<<"Welcome! This program converts the English sytems units to metric system units."<<endl;
}

void get_numbers(int& input1, int& input2)
{
  using namespace std;
 cout<<"Enter the number of feet and inches integers separately: "<<endl;
 cin>>input1;
 cin>>input2;
}

double conversion(int feet, int inches)
{ 
  using namespace std;

  double total_meter, end_meter;
  double const foot = 0.3048, inch = 12;

  total_meter = feet+(inches/inch);
  end_meter = total_meter*foot;

  return end_meter;
}

void show_results(int results1, double results2)
{
  using namespace std;
  char action;

  cout<<"The value in metric systems are "<<results1<< " m and "<<results2<< "cm"<<endl;

 do{
  cout<<"Do you want to repeat a new calculation? [Y/y/N/n]"<<endl;
  cin>>action;  
action = toupper (action);
 } while (action == 'y' || action != 'n'); 

 return;

}
I still don't get it. Why my REPEAT LOOP doesn't work?
Seems to work for me. What is the exact input you're giving the program that's not working for you?

And, your y/n test still isn't right. Besides the uppercase issue (which you still haven't solved, you're not doing anything with action after you test it in the do-while loop. You exit the routine, and the value in action is lost.
Here is the problem, this is how it executes my repeat loop:

1
2
3
4
5
6
7
8
9
10
11
12
13
Welcome! Enter 1 to proceed to a metric system to English system conversion or enter 2 to proceed to an English system to metric system conversion.
1
Welcome! This program converts the metric sytems units to English system units.
Enter the number of meter in integers:
10
The value in metric systems are 32 lb and 9 inch
Do you want to repeat a new calculation? [Y/y/N/n]
y
Do you want to repeat a new calculation? [Y/y/N/n]
y
Do you want to repeat a new calculation? [Y/y/N/n]
n
Do you want to repeat a new calculation? [Y/y/N/n]



You're making the action uppercase yet you're testing against lowercase letters.
that isn't the problem. As i said. I have used toupper. So, it will handle that problem. My ONLY problem is where am i supposed to place my REPEAT loop in my program. That's all. why...
It is the problem. toupper() will change action to an uppercase letter. Then you compare it to some lowercase letters.
Pages: 12