# NEED QUICK HELP WITH LOOPS PLEASE

Page 1 of 1

## 2 Replies - 1550 Views - Last Post: 17 May 2001 - 04:36 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=2368&amp;s=403f4634bf5c18a6b324d7de6dd5c927&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 delirium

Reputation: 0
• Posts: 4
• Joined: 16-May 01

# NEED QUICK HELP WITH LOOPS PLEASE

Posted 16 May 2001 - 09:57 PM

im making a program in C++ to convert american measurements to metric. i have it done except im still new and im not too familiar with loops. could someone please tell me how my loops should look like? and dont worry about the calculation part thats my friends job.

#ifndef tree_h
#define tree_h
#include <iostream.h>
#include <iomanip.h>
#include <ctype.h>

#define franc 5.2
#endif

MAIN
#include "conversion.h"

int main(void)
{

// LOCAL DECLARATIONS
char choice, subchoice;
int inch, foot, yard, mile, fahrenheit, pound, ounce, dollar, quart, teaspoon, degreerad, degreegra;
float converted

//PROTOTYPES
void extern input (char &, char &, int &, int &, int &, int &, int &, int &, int &,
int &, int &, int &, int &, int &);

float extern calc (char, char, int, int, int, int, int, int, int, int, int, int,
int, int, float);

void extern output_choices (char, char);
void extern output_distance (int, int, int, int);
void extern output_temperature (int);
void extern output_weight (int, int);
void extern output_currency (int);
void extern output_capacity (int, int);
void extern output_math (int, int);

//EXECUTABLE CODE
cout << setiosflags (ios::fixed|ios::showpoint) << setprecision(2);

do
{
converted = 0.0;
do
{
input(choice, subchoice, excess);
if (choice !='E')
{
converted = calc_convert(choice, subchoice, inch, foot, yard, mile, fahrenheit,
pound, ounce dollar, quart, teaspoon, degreerad, degreegra, excess);

output(choice, subchoice, inch, foot, yard, mile, fahrenheit,
pound, ounce dollar, quart, teaspoon, degreerad, degreegra);

converted += converted;
}
}
while(choice != converted);

output_total (total);

do
{
cout << "
Any More Conversions?(y,n)";
cin >> resp;
resp = toupper (resp);

}
while(resp !='Y' && resp !='N');

}
while(resp =='Y');
return 0;

}

MAIN ENDS

INPUT

#include "conversion.h"

void input (char & choice, char & subchoice, int & inch, int & foot, int & yard, int & mile,
int & fahrenheit, int & pound, int & ounce, int & dollar, int & quart, int & teaspoon
int & degreerad int & degreegra int & excess)
{

// LOCAL DECLARATIONS
int stump;

// PROTOTYPE
void input_stump (int &);

// EXECUTABLE CODING
excess = 0;

do
{
cout << "
Enter Choice:([D]istance,[T]emperature,[W]eight,[Cu]rrency,[Ca]pacity,
[M]ath,[E]nd)";
cin >> choice;
choice = toupper(choice);
}
while(choice != 'D' && choice != 'T' && choice !='W' && choice !='Cu' && choice != 'Ca'
&& choice != 'M');

if(choice !='E')
{
do
{
cout << "
Enter Distance SubChoice: (nch,[F]oot,[Y]ard,[M]ile)";

cout << "
Enter Temperature SubChoice: ([F]ahrenheit)";

cout << "
Enter Weight SubChoice: ([P]ound,[O]unce)";

cout << "
Enter Currency SubChoice: ([D]ollar) ";

cout << "
Enter Capacity SubChoice: ([Q]uart,[T]easpoon)";

cout << "
Enter Math SubChoice: (Degree to convert to [R]adian, Degree to convert to [G]rad)";

cin << ;
}
while (conversion <= 0);

if (choice == 'S')
{
for (stump = 1; stump <= num; ++stump)
input_stump(excess);
}
}
return;
}

void input_stump (int & excess)
{

// LOCAL DECLARATIONS
char over 10;

// EXECUTABLE CODING
do

{
cout << "
Is stump size>" << EXCESS_SIZE << "?"
cin >> over10;
over10 = toupper(over10);

}
while(over10 != 'Y' && over10 != 'N');

if(over10 == 'Y')
++ excess;
return;

}

INPUT ENDS

OUTPUT

#include "conversion.h"

void output_choices (char choice, char subchoice)
{
cout << 't' << "Choice:" << choice << endl;

cout << 't' << "SubChoice:" << subchoice << endl;
return;
}

void output_distance (int inch, int foot, int yard, int mile,
float converted)
{

cout << 't' << inch << "tConverted to Metric:" << 't' << converted
<< endl;

cout << 't' << foot << "tConverted to Metric:" << 't' << converted
<< endl;

cout << 't' << yard << "tConverted to Metric:" << 't' << converted
<< endl;

cout << 't' << mile << "tConverted to Metric:" << 't' << converted
<< endl;
return;
}

void output_temperature (char fahrenheit, float converted)
{
cout << 't' << fahrenheit << "tConverted to Metric:" << 't'
<< converted << endl;
return;
}

void output_weight (int pound, int ounce, float converted)
{
cout << 't' << pound << "tConverted to Metric:" << 't'
<< converted << endl;

cout << 't' << ounce << "tConverted to Metric:" << 't'
return;
}

void output_currency (int dollar, float dollar)
{
cout << 't' << dollar << "tConverted to Metric:" << 't'
<< converted << endl;

return;
}

void output_capacity (int quart, int teaspoon, float converted)
{
cout << 't' << quart << "tConverted to Metric:" << 't'
<< converted << endl;

cout << 't' << teaspoon << "tConverted to Metric:" << 't'
<< converted << endl;

return;
}

void output_math (int degree, float converted)
{
cout << 't' << degree << "tConverted to Metric:" << 't'
<< converted << endl;

return;
}

Is This A Good Question/Topic? 0

## Replies To: NEED QUICK HELP WITH LOOPS PLEASE

### #2 delirium

Reputation: 0
• Posts: 4
• Joined: 16-May 01

## Re: NEED QUICK HELP WITH LOOPS PLEASE

Posted 16 May 2001 - 10:07 PM

sorry i should of been more specific :o i think i have it figured out so people can choose from the different measurements like distance and temperature to convert.

but i need subtopics so when someone chooses distance it splits into subchoices like inch, foot, yard...etc.

any idea of how to do this and where it should be specified?

### #3 nighthawk

• D.I.C Lover

Reputation: 0
• Posts: 1,269
• Joined: 11-April 01

## Re: NEED QUICK HELP WITH LOOPS PLEASE

Posted 17 May 2001 - 04:36 PM

when they insert what they want to convert (i.e. distance, temperature), i'd do an if/else statement, that says if input = distance, and then output a list that has numbers next to it
1.feet
2.inches
3.centimeters
etc
then have them choose what they want.

i hope that this helps you.