I have an assignment on currency I turned it in, and it is not right by no menas. I had no loops in any module, can anyone explain how to do a loop?

FOR or WHILE

as in,

for (count=1; count<= MAX; count++)
{
     <stuff>
}

...

while(count <= MAX)
{
     <stuff>
}

the FOR loop will perform <stuff> MAX number of times before continuing with the rest of the program. note that the variable "count" is incremented once each time the loop is executed, until it exceeds the value MAX. "MAX" doesnt have to be a variable. it could simply be hardcoded as 10 or 20 or 1000 or whatever; i just put it as a variable for illustration.

WHILE works similarly, but in this case the variable "count" is modified somewhere in the block of the code (<stuff>)... make sure that "count" actually can become greater than MAX, or you will be stuck in the while loop forever. infinite loops are a common programming bug.

WHILE loops are often used with various conditions such as

while(reverseCount > 0)

or

while(flag != 1)

etc.


.

Here is what I have so far, I have corrected what I had orginally though I am sure it needs more tweeking to be correct.
Main Module
Declare Currency Type as Integer
Declare Foreign Currency as Real
Declare US Dollar as real
Do while User continues
Call Display Menu Module
Call Get Foreign Currency Value Module
Call Convert Currency Module
Call Display Results Module
End Loop
End Main Module
Display Menu Module
Loop goes here Not sure about it though??
Display "Currency Converter"
Display "Select a Currency"
Display "1 Canadian Dollars"
Display "2 Mexican Pesos"
Display "3 English Pounds"
Display "4 Japanese Yen"
Display "5 French Francs"
Display "6 Done"
Input Foreign Currency Type
if Foreign currency type ≤ 5 continue to Calculate Rate
Else
display "Invalid Data Type Please Select again"
End if
End Display Menu Module

Get Foreign Currency Value Module
Display " Enter a Currency value (0-100,000)"
Input Foreign Currency value
if Foreign Currency Value <0 or Foreign Currency Value >100,000
Else Display "Invalid Entry, Please try again"
End Get Foreign Currency Value Module
Convert Currency Module
Select Foreign Currency Type
Case 1: Canadian
Set Rate= 1.4680
Case 2: Mexican
Set Rate= 9.5085
Case 3: English
Set Rate=1.6433
Case 4: Japanese
Set Rate = 104.9200
Case 5: French
Set Rate = 6.2561
US Dollar Value=Foreign Currency Value*Rate
End Convert Currency
Display Results
Declare Currency as String
Case 1: Canadian
Currency="Dollars"
Case 2: Mexican
Currency="Pesos"
Case 3: English
Currency="Pounds"
Case 4: Japanese
Currency="Yen"
Case 5: French
Currency="Francs"
Display" The Value of Foreign Currency Value" is "US Dollar Value" "Dollars"
End Display Results

um... yes?

umm yes?? What does that mena?

Sounds like an "existential matter" instead of a programming issue...

the correct approach of a for loop is "when you know how may iterations you have to do" this is, if you're going to repeat the piece of code just 10 times, use a for

the approach of a while loop is more than a "conditional loop" this is, when you don't know the total amount of iterations, but when to stop, then you may either use a while (if there's a condition to loop) or a do... while (if you know you should do the job at least once.

The performance is almost the same for both for, and while loops the compiler always do an "internal while" (even when exists an internal for-like cpu instruction loop) the compiler likes to make a goto-break statement, this is because the for can also be used to simulate whiles, and infinite loops (this isn't always a mistake... everybody have a infinite loop on his/her os, called idle process), this is also used by schedulers and background processes (naturally, to break an infinite loop you use a signal) the term may be "indetermined loops"

Is what I have above even close?

It's correct, the pseudocode. It's very VBish, but it's correct.

umm yes?? What does that mena?

it means i looked through your entire post and couldn't find a single question.

You can use do while loop. for eg:
char ch;
do
{
stuff to be done
.
.
.
printf("Do u want to continue(y/n):");
scanf("%c",&ch);
}while(ch!='n');

.
.
.
remaining stufff....

what is the exact thing you need?just figure out your problem and ask me i will help you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.