Thread: Question regarding addition:

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    2

    Question regarding addition:

    Here is my current code for a calculator; I'm struggling in getting it to display the fourth category total amount which would be sale amount + tax sales amount. Any hints here would be appreciated.

    Code:
    #include <stdio.h>
    
    #define DelMar 7.25
    #define Encinitas 7.5
    #define LaJolla 7.75
    
    float user_input(){
    float amount;
    printf("Please input sales amount\n");
    scanf("%f", &amount);
    return amount;
    }
    int main(){
    float sales = 125.00;
    sales = user_input();
    if (sales < 0.00) {
    	printf("A sale cannot be negative. Please try again");
    	exit(-1);
    }
    
    printf("Tax Calculator for Kudler Fine Foods\n\n\n");
    
    printf("Store Location\tSales Amount\tTax Percentage\tTax Amount\tTax Amount\tTotal Amount\n");
    printf("Del Mar Store\t$%.2f\t\t%.2f%%\t\t%.2f%\t\n",sales, DelMar, sales*DelMar/100);
    printf("Encinitas Store\t$%.2f\t\t%.2f%%\t\t%.2f%\t\n",sales, Encinitas, sales*Encinitas/100);
    printf("La Jolla Store\t$%.2f\t\t%.2f%%\t\t%.2f%\t\n",sales, LaJolla, sales*LaJolla/100);
    printf("                        Press the enter key to exit the calculator\n");
    getch();
    
    return 0;
    
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    If sale amount is "sales" and sales tax is "sales*DelMar/100", then sales + sales tax would be "sales + sales*DelMar/100".

  3. #3
    Registered User
    Join Date
    Jun 2008
    Posts
    2
    Simple enough. Don't know why but I was trying to get it done in a more complicated way. Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory question (pointer related)
    By cjschw in forum C++ Programming
    Replies: 2
    Last Post: 04-30-2004, 01:09 PM
  2. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  3. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM
  4. Question about linked lists.
    By cheeisme123 in forum C++ Programming
    Replies: 6
    Last Post: 02-25-2003, 01:36 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM