I have read other threads and it helped me solve my problem sort of. Can someone please tell me why I had to add two getchar(); in my code in order for it to work. I took the Source code and compilied it in both windows and linux then ran it and got the same results.
Code:
/********************************
* FileName: cbcalc.c *
* *
* Purpose: Caluclate checkbook *
* *
* Author: Josh Stephens *
* *
* Date Created: 10/18/2005 *
* *
* Revision: 1.0 *
********************************/
#include <stdio.h>
int main()
{
float starting_balance; //Balance Currently in checkbook
float trans_amount; //Amount Transaction Was For
float ending_balance; //Amount after Transaction takes place
char trans_type; //(D) for Deposit and (W) for Withdraw
// Module 1. Get information From Users
printf("Please enter your starting balance:\t$");
scanf("%f",&starting_balance);
printf("Please enter (D) for Deposit and (W) for withdraw:\t");
scanf("%s",&trans_type);
printf("Please enter your Amount for Transaction:\t$");
scanf("%f",&trans_amount);
// Module 2. Take input and make decision then calculate based on transaction type
if(trans_type == 'D')
{
ending_balance = starting_balance + trans_amount;
}
else
{
ending_balance = starting_balance - trans_amount;
}
// Module 3. Print information Back to user
printf("Your new balance is now: \t$%.2f",ending_balance);
printf("\nPress any Key to quit!");
getchar();
getchar();
return(0);
}
Thanks for all the help. I am very new to programming in C.