C examples for Language Basics:Console
Do calculation based on user choice
#include <stdio.h> int main() { //from w w w .j ava 2 s. com int iSelection = 0; float fTransAmount = 0.0; float fBalance = 100.25; printf("1\tDeposit Funds\n"); printf("2\tWithdraw Funds\n"); printf("Enter your selection: "); scanf("%d", &iSelection); if (iSelection == 1) { printf("\nEnter fund amount to deposit: "); scanf("%f", &fTransAmount); printf("\nYour new balance is: $%.2f\n", fBalance + fTransAmount); } if (iSelection == 2) { printf("\nEnter fund amount to withdraw: "); scanf("%f", &fTransAmount); if (fTransAmount > fBalance) printf("\nInsufficient funds\n"); else printf("\nYour new balance is $%.2f\n", fBalance - fTransAmount); } }