simple calculator

This is a discussion on simple calculator within the C Programming forums, part of the General Programming Boards category; I made some simple basix calculator in dev c++ like c program and I would like to change it a ...

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    5

    simple calculator

    I made some simple basix calculator in dev c++ like c program and I would like to change it a bit. Does anyone can help me make that this program will calculate like this:
    you write 5*5 and it will write 25 and it will set in you new line and you will be able to write numbers again and it will calculate it again.
    Now program calculate it and it just close after that.
    It look like this:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    int main(int argc, char *argv[])
    {float a,b,r;
    char op;
    scanf("%f%c%f", &a, &op, &b);
    switch(op)
    {case '+':r=a+b;
    printf("%f", r);
    break;
    case '-':r=a-b; 
    printf("%f", r); 
    break;
    case '*':r=a*b; 
    printf("%f", r); 
    break;
    case '/':r=a/b; 
    printf("%f", r); 
    break;
    default: printf ("Nekaj ne delas prav"); }
    
    
       system("PAUSE"); 
      return 0;
    }
    
    #include <stdio.h>
    #include <stdlib.h>
    int main(int argc, char *argv[])
    {float a,b,r;
    char op;
    scanf("%f%c%f", &a, &op, &b);
    switch(op)
    {case '+':r=a+b;
    printf("%f", r);
    break;
    case '-':r=a-b; 
    printf("%f", r); 
    break;
    case '*':r=a*b; 
    printf("%f", r); 
    break;
    case '/':r=a/b; 
    printf("%f", r); 
    break;
    default: printf ("Nekaj ne delas prav"); }
    
       system("PAUSE"); 
      return 0;
    }
    Any idea what do I have to change to don't stop after 1st calculation ?




    Symcy

  2. #2
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,659
    You posted the code twice for some reason.

    Can you apply some of the ideas from here: Cprogramming.com Tutorial: Loops

  3. #3
    Registered User
    Join Date
    Jan 2011
    Posts
    5
    Quote Originally Posted by whiteflags View Post
    You posted the code twice for some reason.

    Can you apply some of the ideas from here: Cprogramming.com Tutorial: Loops
    I double posted it because of some problems with my explorer ...
    I already changed that but it comes back even if I edit that.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple Socialising Chat Bots
    By bengreenwood in forum C++ Programming
    Replies: 10
    Last Post: 11-28-2007, 07:42 AM
  2. simple calculator
    By HunterCS in forum C++ Programming
    Replies: 10
    Last Post: 07-18-2007, 06:51 AM
  3. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM
  4. A Simple Calculator Program Not Working
    By oobootsy1 in forum C++ Programming
    Replies: 9
    Last Post: 01-09-2004, 08:34 PM
  5. Java Calculator
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 11-12-2002, 07:39 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21