Programming in c and we must use Miracle c for this course.
I had my USD * MXN working prior to adding a numbers only validation.
Now the code works as I want it to except for the correct calculation.
Any suggestions would be appreciated.
#include<stdio.h>
#include<ctype.h>
#include <math.h>
int is_number(char * pchar, int lnum){
int i, is_num=0;
for(i=0; i<lnum; i++){
if(!isalnum(*pchar)) break;
// printf("%c - ",*pchar);
if(!isdigit(*pchar)){
is_num++;
break;
}
pchar++;
}
//printf("\nis_num = %i\n",is_num);
return is_num;
}
int main(void){
float USD = 1.00; /*1.00 USD = 1.00 United States Dollar*/
float MXN = 13.1960; /*1.00 USD = 13.1990 Mexico Pesos HTTP://MONEY.CNN.COM\DATA\CURRENCY AS OF 25 MAY 2009*/
float totalPesos = 0.0;
char num[50];
totalPesos = USD * MXN;
printf("\n\tUSD to PESO Currency Conversion");/*Program or code title shown to the user*/
printf("\n");
printf("\nHow many U.S. Dollars do you want to convert to Mexican Pesos?\t$\a");
scanf("%s",num);
if(!is_number(num,50)){
printf ("\n");
printf ("With that amount of US Dollars you will get...\n");/*statement that user will see on the top of the convertions*/
printf ("\n");/*Add a line in between each output*/
printf ("\t%3.2f\tMXN PESOS\n", totalPesos);
printf ("\tConversion complete \"PLEASE PUSH ENTER TO EXIT\"\a");
}else{
printf("INVALID INPUT\n");
printf ("\tPLEASE PUSH ENTER TO EXIT\"\a");
}
getch();
}