Omnimaga

Calculator Community => TI Calculators => Calculator C => Topic started by: simonepsp on April 16, 2013, 02:04:42 pm

Title: Simple calculator program
Post by: simonepsp on April 16, 2013, 02:04:42 pm
Hi :)

I want to develop a little program that asks me two input numbers (eg. 5 & 10). And do some calcs on it...

Eg. User enter two numbers (eg. a=5, b=10), program give user a numeric output (a + b = 15)

I know how do it in C:
Quote

    #include <stdio.h>
    int a,b,c;
    main ()

        {
        scanf("%d",&a);
        scanf("%d",&b);
        c=a+b;
        printf("%d\n",c);
        }



But I don't know how do it in C (with Tinspire libraries). Anyone could give me a code example? I'm a C noob :P

Thank you
Title: Re: Simple calculator program
Post by: Lionel Debroux on April 16, 2013, 02:11:45 pm
On the computer, you could do it better, by using a proper prototype for main(), returning a value, making the variables local to main - you probably compiled this snippet with a lenient compiler and without warning switches ;)
(for extra bonus points, check for overflow on the result of the addition)

On the Nspire, you could input strings somehow (by reading the keyboard's keys), and use, for instance, strtoul to convert the string to an integer. The NspireIO lib should save you some work, BTW :)
Title: Re: Simple calculator program
Post by: simonepsp on April 16, 2013, 02:32:49 pm
On the computer, you could do it better, by using a proper prototype for main(), returning a value, making the variables local to main - you probably compiled this snippet with a lenient compiler and without warning switches ;)
(for extra bonus points, check for overflow on the result of the addition)

On the Nspire, you could input strings somehow (by reading the keyboard's keys), and use, for instance, strtoul to convert the string to an integer. The NspireIO lib should save you some work, BTW :)

Can you write me a start code? :) because I'm a very beginner and I don't know how do it :)

Thank you
Title: Re: Simple calculator program
Post by: floris497 on April 17, 2013, 05:41:56 am
do you want to use Nspire Basic or ndless C?
Title: Re: Simple calculator program
Post by: ElementCoder on April 17, 2013, 08:01:52 am
But I don't know how do it in C (with Tinspire libraries). Anyone could give me a code example? I'm a C noob :P
Juding from the first post he wants to use ndless C ;) On a side note, you may want to put your code in [code] code here[/code] tags