Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Simple Functions In this workshop, you are to design a function that returns a s

ID: 3624393 • Letter: S

Question

Simple Functions In this workshop, you are to design a function that returns a single value and to use that function in a program. Learning Outcome Upon successful completion of this workshop, you will have demonstrated the abilities to analyze a small problem that lends itself to a programming solution design an algorithm to solve the problem write code to implement the solution apply structured programming principles, including single-entry/single-cxit logic, modularity and localization of variables, when writing the code. compose technical program documentation using internal comments and descriptive identifiers. Financial Calculator Design and code a program that performs two financial calculations: future value and present value. Your program prompts for and accepts a principal amount, an interest rate per year, and the number of years If the number of periods is zero then the calculated amount is a present value (principal). Design your program according to structured design principles and include a function that can be used in both calculations as well as in other applications. Do not use any library functions apart from functions. Preface your function header with a comprehensive description of the function purpose, the function parameters and the function return value. The output from your program should look something like:

Explanation / Answer

Program has 1 file:main.cpp

#include <stdio.h>

#include <stdlib.h>

#include <conio.h>

float laitong(float );

float laitong(float x, int n)

{

      int i;

      float flai=1;

      for (i=1; i<=n; i++)

      {

            flai=flai*(1+x);

      }

      return flai;

}

int main()

{

    system("cls");                                          //Lam sach man hinh

    while(1)                                                //Tao vong lap while

    {

            system("cls");

                  int choice, isoky;                                          //Khai bao bien

                  float ftiengoc, flaisuat, ftaikhoan;

            printf(" Choose one of the following options: ");

            printf(" 1. Test saving account ");

                  printf(" 0. Exit ");

            printf(" Your selection (0 -> 1): ");

            scanf("%d",&choice);

            if(choice==0) break;                                   //Kiem tra lua chon choice

                  if(choice!=0 && choice!=1)

                  {

                        printf("**Invalid choice. Try again.**");

                  }

                  if(choice ==1)

                  {

                        printf("Principal = ");

                        scanf("%f", &ftiengoc);

                        printf("Annual rate = ");

                        scanf("%f", &flaisuat);

                        printf("No of years = ");

                        scanf("%d", &isoky);

                        ftaikhoan=ftiengoc*laitong(flaisuat, isoky);

                        printf("Principal = %.2f Amount after %d years = %.2f ", ftiengoc, isoky, ftaikhoan);

                  }

            printf("Press any key to continue... ");      //Thong bao thuc hien thao tac tiep theo

            getch();                                           //Dung man hinh de nhin thay dong chu: Press any key to continue...

    }

      return 0;

}

#include <stdio.h>

#include <stdlib.h>

#include <conio.h>

float laitong(float );

float laitong(float x, int n)

{

      int i;

      float flai=1;

      for (i=1; i<=n; i++)

      {

            flai=flai*(1+x);

      }

      return flai;

}

int main()

{

    system("cls");                                          //Lam sach man hinh

    while(1)                                                //Tao vong lap while

    {

            system("cls");

                  int choice, isoky;                                          //Khai bao bien

                  float ftiengoc, flaisuat, ftaikhoan;

            printf(" Choose one of the following options: ");

            printf(" 1. Test saving account ");

                  printf(" 0. Exit ");

            printf(" Your selection (0 -> 1): ");

            scanf("%d",&choice);

            if(choice==0) break;                                   //Kiem tra lua chon choice

                  if(choice!=0 && choice!=1)

                  {

                        printf("**Invalid choice. Try again.**");

                  }

                  if(choice ==1)

                  {

                        printf("Principal = ");

                        scanf("%f", &ftiengoc);

                        printf("Annual rate = ");

                        scanf("%f", &flaisuat);

                        printf("No of years = ");

                        scanf("%d", &isoky);

                        ftaikhoan=ftiengoc*laitong(flaisuat, isoky);

                        printf("Principal = %.2f Amount after %d years = %.2f ", ftiengoc, isoky, ftaikhoan);

                  }

            printf("Press any key to continue... ");      //Thong bao thuc hien thao tac tiep theo

            getch();                                           //Dung man hinh de nhin thay dong chu: Press any key to continue...

    }

      return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote