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();
}

Well, and where is the conversion formula? Now you have a very profitable business (fixed 13.20 pesos for 10$, 100$ etc).

Other code defects:
1. The second is_number parameter defines a number of chars to be checked. However the 1st argument is C string and it can be shorter than 50 so you test garbage chars after terminating zero byte.
2. Your is_number algorithm is incorrect. For example, try "===" string: is_number returns TRUE...
3. Don't glue long comments to code lines.
4. Don't use beeps in user interface: it's annoying. Don't use too long prompts: no room for user input in a typical console line.
... and so on ...

And the last counter-question: what's your PROBLEM? Any suggestions is not a problem ;)

Next time use code tag with the language specifier:
[code=c] source

[/code]

Before I was instructed that I had to ensure that only numbers, and greater than zero are needed for user input. the following was my working code and calculations. ( if numbers only were inputted)

#include <stdio.h>
#include <math.h>

main()
{

float USD = 1.00; 
float MXN = 13.1960; 
char chrUserInput[9];
float totalPesos = 0.0;

printf("\n\tUSD to PESO Currency Conversion");
printf("\n");
printf("\nHow many U.S. Dollars do you want to convert to Mexican Pesos?\t$\a");
scanf("%f", &USD);

//*Calculation*//

totalPesos = USD * MXN;


//*Amount Converted will be show*//

printf ("\n");
printf ("With that amount of US Dollars you will get...\n");
printf ("\n");
printf ("\t%3.2f\tMXN PESOS\n", totalPesos);



printf ("\tConversion complete \"PLEASE PUSH ENTER TO EXIT\"\a");

getch();
}
main()

what the hell is that?

main must be an int, and it must take an argument

int main(void)

other than that, i dont understand what your question is. i'm still not sure if you even asked a question.

let me take a guess... is your question: "why doesn't this code work with Miracle C ?"

is that it?

> we must use Miracle c for this course.
Drop the course.
The teacher is AN IDIOT.
You will learn nothing of any value at all from that doofus.

That compiler is probably the worst one of any kind, and certainly THE WORST one which has the gall to ask for money - now that's the real miracle.

Damn.
Yes he said we have to use Miracle C.
That is what he is going to use to check it.
We have to send him the *.c file and the *.exe file for him to check both.

We have to create a Currency Conversion from the US Dollar to any we pick.

And now, It must also allow only input from numbers greater than zero.

OK, Miracle or not Miracle - it's the other story...
You didn't answered the key question: what's is your problem?

Didn't you familiar with school-level arithmetics (where is conversion formula)?

Why you erased int check code instead of correct it?

Damn.
Yes he said we have to use Miracle C.
That is what he is going to use to check it.
We have to send him the *.c file and the *.exe file for him to check both.

Salem is absolutely right: you need to drop this class, and demand your money back. this class is a joke and your "teacher" is a damn fool.

you'll do better to study any number of free tutorials you can find online.

In fact, tell your "teacher" to come on here and explain why he thinks using Miracle C is a good idea.


.

This code below worked until I have to add what he asked for.
Calculations and all
I am attending University of Phoenix.
I cannot just drop this class now.

I am still learning, I don't feel I should be put to shame because I do not know what you professionals know. I am just starting out.

I am willing to learn

Before I was instructed that I had to ensure that only numbers, and greater than zero are needed for user input. the following was my working code and calculations. ( if numbers only were inputted)

#include <stdio.h>
#include <math.h>

main()
{

float USD = 1.00; 
float MXN = 13.1960; 
char chrUserInput[9];
float totalPesos = 0.0;

printf("\n\tUSD to PESO Currency Conversion");
printf("\n");
printf("\nHow many U.S. Dollars do you want to convert to Mexican Pesos?\t$\a");
scanf("%f", &USD);

//*Calculation*//

totalPesos = USD * MXN;


//*Amount Converted will be show*//

printf ("\n");
printf ("With that amount of US Dollars you will get...\n");
printf ("\n");
printf ("\t%3.2f\tMXN PESOS\n", totalPesos);



printf ("\tConversion complete \"PLEASE PUSH ENTER TO EXIT\"\a");

getch();
}

OK, here's what you can try.

Find ONE simple line to add to your program which breaks it, then go and ask your teacher for advice.
That should be easy, the compiler is crap, you'll easily run into a problem.
If they "um, and ahh" AT ALL, then the case is proven.

At the same time, tell them that this other FREE compiler had no trouble at all with the code, and that in fact you've already finished the assignment using the new compiler.

Discuss the problem with your fellow students. They're all in the same boat, and I guess having the same trouble.

A popular choice is http://www.codeblocks.org/downloads/5
Get codeblocks-8.02mingw-setup.exe

> I am attending University of Phoenix.
So you're paying for this with your own money (if I understand the US system).
And all your colleagues are paying for it as well.
Collectively, you should be able to demand a better quality teacher than the has-been (or never-was) you're stuck with at the moment.

This article has been dead for over six months. Start a new discussion instead.