Author Topic: Simple calculator program  (Read 3910 times)

0 Members and 1 Guest are viewing this topic.

Offline simonepsp

  • LV2 Member (Next: 40)
  • **
  • Posts: 20
  • Rating: +4/-1
    • View Profile
Simple calculator program
« 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

Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: Simple calculator program
« Reply #1 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 :)
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.

Offline simonepsp

  • LV2 Member (Next: 40)
  • **
  • Posts: 20
  • Rating: +4/-1
    • View Profile
Re: Simple calculator program
« Reply #2 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

Offline floris497

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 210
  • Rating: +8/-0
    • View Profile
Re: Simple calculator program
« Reply #3 on: April 17, 2013, 05:41:56 am »
do you want to use Nspire Basic or ndless C?

Offline ElementCoder

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 611
  • Rating: +42/-2
    • View Profile
Re: Simple calculator program
« Reply #4 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

Some people need a high five in the face... with a chair.
~EC