473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

if else statements

if i want to have a selection that uses letters such as m for metric, e for english, or q for quit to select which part of my if else statement i want to run... how would i set that up... i want to say that it would be....

Expand|Select|Wrap|Line Numbers
  1. cin>> letter;  
  2. if(letter == 'm')
Oct 11 '07 #1
6 1670
Banfa
9,065 Expert Mod 8TB
That looks about right, or you may wish to consider using a switch statement if there are going to be a lot of options.
Oct 11 '07 #2
That looks about right, or you may wish to consider using a switch statement if there are going to be a lot of options.

I only have those three choices. so i figured i could do if, then if else, then if else again and it would be fine.... also im getting an error because im using if outside of my int main() for void functions... am i not allowed to do that?
Oct 11 '07 #3
Can someone tell me why i can't do this and help me out with what i should do...

Expand|Select|Wrap|Line Numbers
  1. if(letter == 'm' || letter == 'M')
  2.  
  3. {void get_numbers(double& input1, double& input2)
  4.  {
  5.   using namespace std;
  6.   cout<< "Enter first number as meters and second as centimeters.\n";
  7.   cin>> input1
  8.      >> input2;
  9.   input1 = input1 * 3.2808399;
  10.   input2 = input2 * .393700787;
  11.  }
  12.  
  13.  void show_results(double output1, double output2)
  14.  {
  15.   using namespace std;
  16.   cout<< "Feet: "<<output1<<" Inches: "<<output2<<endl;
  17.  }
  18. }
  19.  
Oct 12 '07 #4
RRick
463 Expert 256MB
Are you saying you have an if-else conditional outside of any function? That won't work. They need to be inside a function or method.

Perhaps a code snippet would help.
Oct 12 '07 #5
Are you saying you have an if-else conditional outside of any function? That won't work. They need to be inside a function or method.

Perhaps a code snippet would help.


Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.   char letter;
  4.  
  5.   cout<<"Metric to English and English to Metric converter.\n"
  6.       <<"For Metric to English type m, for Enlish to Metric type E, Type q to quit.\n";
  7.   cin>>letter;
  8.  
  9.      double first_num, second_num;
  10.  
  11.      get_numbers(first_num, second_num);
  12.      show_results(first_num, second_num);
  13.      return 0;
  14. }
  15.  
This is my main part... im trying to run three different times... one being running from metric to english... or english to metric... or just quit.... and i figured i could use more void functions for when i go english to metric....
Oct 12 '07 #6
weaknessforcats
9,208 Expert Mod 8TB
This is my main part... im trying to run three different times... one being running from metric to english... or english to metric... or just quit.... and i figured i could use more void functions for when i go english to metric....
Have you considered that you never use the letter? So how do your functions know whether it is English or Metric?

You might pass along the letter as a third argument.
Oct 12 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Brittany | last post by:
can someone explain to me what if else staments do and what while statements do.
11
by: dmbkiwi | last post by:
I am new to this group, and relatively new to python programming, however, have encountered a problem I just cannot solve through reading the documentation, and searching this group on google. I...
33
by: Diez B. Roggisch | last post by:
Hi, today I rummaged through the language spec to see whats in the for ... else: for me. I was sort of disappointed to learn that the else clauses simply gets executed after the loop-body -...
6
by: Bart Nessux | last post by:
Should an if statement have a corresponding else statement? Or, is it OK to have an if statement by itself. For completeness, it seems the two should be together, but from experience I know that a...
27
by: Ron Adam | last post by:
There seems to be a fair amount of discussion concerning flow control enhancements lately. with, do and dowhile, case, etc... So here's my flow control suggestion. ;-) It occurred to me (a...
3
by: Patrice | last post by:
Hi, I need to do multi-conditional statements like below, but this error is displayed : Expected 'End' /myFilepath, line x else response.write(arrCorpo(sparam,sdiv)) end if I don't...
3
by: Amy | last post by:
Hi, I have 6 If Then Else statements I was supposed to write. I did so but I know that they have to be wrong because they all look the same. Could someone take a look at them and point me in the...
2
by: pradeep.thekkottil | last post by:
I'm setting up an auction website using PHP and MySQL. There in the section where logged in members can put up new auction in a form, I want to run a form validation where I used if else statements...
23
by: bearophileHUGS | last post by:
So far in Python I've almost hated the 'else' of the 'for' loops: - I have problems to remember its meaning; - It gives me little problems when I later want to translate Python code to other...
4
by: Tangleman | last post by:
I have a schema that defines a programming language for a script that drives a sequentially executing process. It defines the structure of a script that has to interact with a pre-existing,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.