Mainly due to the fact my book barely explains array's and doesn't really tell how to manually take user-input and feed it into an array, I am having some issues as of now.
I am trying to take three user defined inputs and store them into my array int real[2].
I get no compile errors as it is, and I am more or less wondering if someone can help me fix up whatever it is that needs fixing. I'v checked online for how to manually put values into an array, however it seems everything I see does it via a counter, which doesn't help me at all. Any help would be appreciated, and i'll post my code below.
(Not finished, just using a printf statement to try and get it so the output is actually real and I know it works properly.)
Code:
/* Loan Calculator
Name: Tyler Sinclair-Day
Purpose: To create a calculator which will use a loan calculation to display a table in which how long a loan will take
to pay of, as well as how much each month will be paid, showing other information as showed in the program
*/
#include <stdio.h>
#include <math.h>
int menu(void); //Prototype for int menu(void) function
int main(void)
{
int real[2];
//Printf showing options to user as what each number represents for entering data//
printf("--------------------\nEnter in the Numeric \nCharacter next to your choice"
"\n--------------------\n\n");
printf("||1. Enter the Principal ||\n"
"||2. Enter the annual interest rate ||\n"
"||3. Enter duration of loan in months ||\n"
"||4. Calculate your loan payments. ||\n"
"||5. Show Loan Table. ||\n"
"||0. Exit program ||\n");
real[2] = menu(); //Calling menu function
//printf("Month::Old Balance::Payment::Interest::Principal::New Balance");
printf("%d and %d and %d", real[0], real[1], real[2]);
getchar();
getchar();
return 0;
}
int menu(void)//Menu function for gathering information from user.
{
//int principal;
//int rate;
//int months;
int real[2];
while ((scanf("%d", &choice)) != 0)//Runs until recieves '0' than quits
{
switch (choice)//Case used for gathering data
{
case 1://Gets data for principal
printf("What is the principal you wish to enter?:\n");
scanf("%d", &real[0]);
break;
case 2://Gets data interest rate
printf("What is the annual interest rate?:\n");
scanf("%d", &real[1]);
break;
case 3://Gets data for months
printf("How many months in which does the loan need to be paid?:\n");
scanf("%d", &real[2]);
break;
case 4://Calculates table
printf("Your payment chart is calculated.\n");
break;
case 5://Prints table out
printf("Below is your loan table.\n\n\n");
break;
case 0:
return 0;
default://Will display message if number >5 or <1 is entered.
printf("You entered a value outside of 1 to 5.\nPlease only use 1, 2, 3, 4, 5 or 0 to exit.\n\n");
}
}
return real[2];
}
/*for(int i = 0;i < months; ++i)
{
printf(" new balance: %d ", newbalance);
principal = principal * (1 + (rate / 12));
oldbalance=oldbalance-principal;
newbalance=oldbalance;
}*/