Question

Create another program that will prompt a user for input file. The user will choose from...

Create another program that will prompt a user for input file. The user will choose from 4 choices:

1. Display all positive balance accounts.

2. Display all negative balance accounts.

3. Display all zero balance accounts.

4. End program.

C PROGRAMMING

my code so far

#include<stdlib.h>

#include<stdio.h>

int main(void)

{

int request;

int account;

FILE *rptr;

char name[20];

double balance;

FILE *wptr;

  

int accountNumber;

  

if((wptr = fopen("clients.dat","w")) == NULL)

{

puts("File could not be opened");

}

else

{

puts("Enter the account, name, and balance.");

puts("Enter EOF to end input");

printf("%s","? ");

scanf("%d%29s%lf", &account, name, &balance);

  

while(!feof(stdin))

{

fprintf(wptr,"%d %s %.2f\n", account, name, balance);

printf("%s","? ");

scanf("%d%29s%lf", &account, name, &balance);

  

}

rewind(wptr);

fclose(wptr);

  

}

  

if((rptr = fopen("clients.dat","r")) == NULL)

{

puts("File could not be opened");

}

else

{

  

  

/*

printf("%s%s%s","Account","Name","Balance");

fscanf(rptr, "%d%29s%lf", &account,name, &balance);

   */

  

while(!feof(rptr))

{

  

printf("%s", "enter request: \n"

   "1. List negative balances. \n"

   "2. List positive balances. \n"

   "3.List Zero balances. \n"

   "4- End program.\n");

scanf("%d", &request);

  

switch(request)

{

case 1:

break;

  

case 2:

break;

  

case 3:

break;

  

default: printf("program is now ending ");

break;

}

  

}

}

  

return EXIT_SUCCESS;

}

MY CODE SO FAR

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

Here the modified code:

//Header file inclusion

#include<stdlib.h>

#include<stdio.h>

// Main method

int main(void)

{

// variable declaration

    int request;

    int account;

     int count;

     int i,accno[100];

double bal[100];

    FILE *rptr;

    char name[20];

    double balance;

    FILE *wptr;

// For storing the user entered file name

     char filename[30];

    int accountNumber;

// Getting the file name from the user

     printf("\n Enter the file Name:");

     scanf("%s",filename);

//Opening the user given file

    if((wptr = fopen(filename,"w")) == NULL)

    {

     puts("File could not be opened");

    }

//if file is successfully opened

    else

    {

     puts("Enter the account, name, and balance.");

     puts("Enter EOF to end input");

    count= scanf("%d%29s%lf", &account, name, &balance);

     while(1)

     {      if(count<3)

               break;

          else

          {

               fprintf(wptr,"%d %s %.2f\n", account, name, balance);

               count=scanf("%d%29s%lf", &account, name, &balance);

          }

     }

rewind(wptr);

fclose(wptr);

}

//Opening the file in read mode

   if((rptr = fopen(filename,"r")) == NULL)

   {

        puts("File could not be opened");

   }

//if successfully opened the file read the

   else

   {

        i=0;

          while(!feof(rptr))

          {

          fscanf(rptr,"%d %s %.2f",&accno[i],name &bal[i]);

          i++;

          }

   }

fclose(rptr);

     printf("enter request: \n"

             "1. List negative balances. \n"

             "2. List positive balances. \n"

             "3.List Zero balances. \n"

             "4- End program.\n");

     scanf("%d", &request);

     switch(request)

         {

          case 1:

//Display the account number which has negative balance

               for(i=0;i<100;i++)

               {

                    if(bal[i]<0)

                    printf("\n%d",accno[i]);

               }

break;

//Display the account that has positive balance

          case 2:

                   for(i=0;i<100;i++)

                    {

                        if(bal[i]>0)

                        printf("\n %d",accno[i]);

                   }

                    break;

   // Display the zero account balance                

          case 3:

                   for(i=0;i<100;i++)

                    {

                        if(bal[i]==0)

                        printf("\n %d",accno[i]);

                   }

                    break;

          default:

printf("program is now ending ");

                    break;

           }

return EXIT_SUCCESS;

}

Output:

The sample output is

Add a comment
Know the answer?
Add Answer to:
Create another program that will prompt a user for input file. The user will choose from...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • create case 4 do Method 1:copy item by item and skip the item you want to...

    create case 4 do Method 1:copy item by item and skip the item you want to delete after you are done, delete the old file and rename the new one to the old name. #include int main(void) { int counter; int choice; FILE *fp; char item[100]; while(1) { printf("Welcome to my shopping list\n\n"); printf("Main Menu:\n"); printf("1. Add to list\n"); printf("2. Print List\n"); printf("3. Delete List\n"); printf("4. Remove an item from the List\n"); printf("5. Exit\n\n"); scanf("%i", &choice); switch(choice) { case 1:...

  • Hardware Inventory – Write a database to keep track of tools, their cost and number. Your...

    Hardware Inventory – Write a database to keep track of tools, their cost and number. Your program should initialize hardware.dat to 100 empty records, let the user input a record number, tool name, cost and number of that tool. Your program should let you delete and edit records in the database. The next run of the program must start with the data from the last session. This is my program so far, when I run the program I keep getting...

  • Within this C program change the input to a file instead of individual input from the...

    Within this C program change the input to a file instead of individual input from the user. You must take the input file name on the command line. Be sure to have simple error checking to be sure the file exists and was successfully opened. The input file will have the following format: First line: Number of students Second Line: Number of grades Third Line: Student Names, space delimited Fourth+ Line(s): Grades for all students for one assignment, space delimited....

  • Identify and list all the User defined Functions to be used in the system #include <stdio.h>...

    Identify and list all the User defined Functions to be used in the system #include <stdio.h> ///for input output functions like printf, scanf #include <stdlib.h> #include <conio.h> #include <windows.h> ///for windows related functions (not important) #include <string.h> ///string operations /** List of Global Variable */ COORD coord = {0,0}; /// top-left corner of window /** function : gotoxy @param input: x and y coordinates @param output: moves the cursor in specified position of console */ void gotoxy(int x,int y) {...

  • I wrote a program which computes the area and perimeter of a square, circle, or rectangle. As you will see in my main function, there is a for loop in which the user is supposed to be able repeat the...

    I wrote a program which computes the area and perimeter of a square, circle, or rectangle. As you will see in my main function, there is a for loop in which the user is supposed to be able repeat the program until they enter "q" to quit. However, my program runs through one time, the prompt appears again, but then it terminates before the user is allowed to respond to the prompt again. I'm not able to debug why this...

  • C++ HELP I need help with this program. I have done and compiled this program in a single file called bill.cpp. It works fine. But I need to split this program in three files 1. bill.h = contains the...

    C++ HELP I need help with this program. I have done and compiled this program in a single file called bill.cpp. It works fine. But I need to split this program in three files 1. bill.h = contains the class program with methods and variables 2. bill.cpp = contains the functions from class file 3. main.cpp = contains the main program. Please split this program into three files and make the program run. I have posted the code here. #include<iostream>...

  • Use two files for this lab: your C program file, and a separate text file containing...

    Use two files for this lab: your C program file, and a separate text file containing the integer data values to process. Use a while loop to read one data value each time until all values in the file have been read, and you should design your program so that your while loop can handle a file of any size. You may assume that there are no more than 50 data values in the file. Save each value read from...

  • C++ HELP I need help with this program. I have done and compiled this program in...

    C++ HELP I need help with this program. I have done and compiled this program in a single file called bill.cpp. It works fine. I am using printf and scanf. Instead of printf and scanf use cin and cout to make the program run. after this please split this program in three files 1. bill.h = contains the class program with methods and variables eg of class file class bill { } 2. bill.cpp = contains the functions from class...

  • Here is a serial program in C and parallel program in OpenMP that takes in a string as input and counts the number of occurrences of a character you choose. Why is the runtime for the output for the O...

    Here is a serial program in C and parallel program in OpenMP that takes in a string as input and counts the number of occurrences of a character you choose. Why is the runtime for the output for the OpenMP parallel program much longer? Serial Program #include <stdio.h> #include <string.h> #include <time.h> int main(){    char str[1000], ch;    int i, frequency = 0;    clock_t t; struct timespec ts, ts2;       printf("Enter a string: ");    gets(str);    int len = strlen(str);    printf("Enter a character...

  • // READ BEFORE YOU START: // You are given a partially completed program that creates a...

    // READ BEFORE YOU START: // You are given a partially completed program that creates a list of students for a school. // Each student has the corresponding information: name, gender, class, standard, and roll_number. // To begin, you should trace through the given code and understand how it works. // Please read the instructions above each required function and follow the directions carefully. // If you modify any of the given code, the return types, or the parameters, you...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT