Hello all,
I'm working on this program (like you haven't seen this before, right) and I'm at the point where I cannot get it to error check when a character is used. I'm using Miracle C to compile and it compiles just fine and runs fine, I would just like a little guidance on where I'm wrong. This is all new to me and I'm learning as best I can.
Also, what would be a better way than to use goto?
Thanks.
Code:
#include <stdio.h>
int main(void)
{
/*
Here is the conversion rate of one currency equivalent to one US dollar.
Comparison price rates acquired on Monday, December 12, 2004
*/
// Declare and define the conversion rate of one currency equivalent to one US dollar.
char cur[6][20]={"Canadian Dollar ", "Exit"}; //name of the lone currency
float rates[5] ={1.2263}; //equivalent exchange rate
float usd; /* US Dollars */
float amount; /* Amount to Convert*/
int r, i;
printf(" Al Emmi's Currency Conversion Program\n\n");
printf("Listed below is one lone country available for conversion\n");
printf(" into a US Dollar equivalent amount \n");
printf("\nHere is your only available choice for conversion: ");
printf("\n (Sorry, budget cuts...d'oh!)\n");
for (i=0;i<2;i++) //a for loop to display the currencies to convert from
{
printf("\n\n\n%d, %s", i+1, cur[i]);
}
fflush(stdin);
choice: printf("\n\nDo me a favor and select that lone currency you want to convert to USD:\n");
printf("\nHint...it's number 1\n");
scanf("%d", &i);
clrscr();
if ((i >2)||(i <=0)) //when the user chooses anything other than choices given
{
printf("Nice try chucklehead, that choice is not available! \n\n");
goto choice;
}else if (i == 2){ //if user just wants to exit because they don't like Canadian mulah
printf("\n\n\n\n Oh, running away already! \n\n");
printf("\n\n\n Well have a groovy day anyway!");
}else{
ask: fflush(stdin);
printf("Very good!\n");
printf("\nSo, how much dough do you want to convert to USD?: \n\n ");
scanf("%f", &amount); //Patiently wait for the user to input something
clrscr();
if (amount <=(float)0) //if user chooses a negative or zero
{
printf("\nYo numbnuts, This thing can't convert to US Dollars\n");
printf(" if the number is zero or negative!\n\n");
goto ask;
}else{
usd = amount /rates[i-1]; /*Convert to US Dollars*/
// Calculation: finding the equivalent amount of the US dollar from the 1 input currency.
printf("\nLike it or not this is what you get: $ %f US Greenbacks! \n\n", usd);
printf(" Now go buy yourself a beer aye!\n");
printf(" So make like a tree, and get outta here!\n");
printf("\n Press and key to exit!\n");
}
}
getch();
return 0;/*End of program*/
}