• C

C program setup

I am working on a checkbook type program. I need to print a statement for
the user to select an option from. Based on that option, the program will
either add money to the "account" or subtract money from it. I need to set
it up so that the user will deposit money first before writing a check. I need to have a loop in the main program and the deposit function. I was going to use a for loop, but I'm not sure where it should go or how to code it. I am new at C programming, and I am trying to learn. This is what I have so far:
#include <stdio.h>
void checking (void)
void deposit (void)
float balance = 0;
int main (void)
int checking ;
int deposit;
{
int ch;
int getfirst (void);
printf("Enter D to deposit money, C to write a check, Q to quit.\n");
printf("Your choice:\n");

if (choice=='D') deposit();

I am not sure how to continue from here. Should I use the scanf function?
What would I use with that option (%s, etc.)? I think I might be setting this up wrong. I would appreciate some
assitance in putting this together.

cbrookhartAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AlexVirochovskyCommented:
#include <stdio.h>
void checking (void)
void deposit (void)
float balance = 0;
int checking ;
int deposit;
int getfirst (void);

int main (void)
{
   int ch,iStop = 0;
  while(!iStop)
  {
  printf("Enter D to deposit money, C    to write a check, Q to quit.\n");
   printf("Your choice:\n");
   ch = getch();
   switch (ch)
      {
        case 'D' : case 'd':
                        deposit();
                        break;
       case 'Q' case 'q' : iStop = 1;
                        break;
       //..... other options
    }
  return 0;
}
I hope, it helps. Alex
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cbrookhartAuthor Commented:
I typed the program up, and compiled it. This is what happened when I compiled it.

a:\checking.c(8) : error C2085: 'deposit' : not in formal parameter list
a:\checking.c(8) : error C2143: syntax error : missing ';' before 'type'
a:\checking.c(8) : error C2085: 'balance' : not in formal parameter list
a:\checking.c(8) : error C2143: syntax error : missing ';' before '='
a:\checking.c(9) : error C2373: 'checking' : redefinition; different type modifiers
        a:\checking.c(6) : see declaration of 'checking'
a:\checking.c(20) : warning C4013: 'getch' undefined; assuming extern returning int
a:\checking.c(24) : warning C4013: 'deposit' undefined; assuming extern returning int
a:\checking.c(31) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

checking.obj - 6 error(s), 2 warning(s)

In the case statement, do I need to have an option for checking? If money is deposited, then the balance has to be incremented and if a check is written, the balance needs to be decreased. Would a statement such as balance = balance + amount work? I'm thinking that will cause another error in the program execution.
0
AlexVirochovskyCommented:
#include <stdio.h>
#include <conio.h>
void Checking (void);
void Deposit (void);
float balance = 0;

int checking ;
int deposit;

int main (void)
{
  int ch,iStop=0;
  while(!iStop)
  {
    printf("Enter D to deposit money, C    to write a check, Q to quit.\n");
    printf("Your choice:\n");
    ch = getch();
    switch(ch)
      {
              case 'D' : case 'd':Deposit();break;
        case'Q': case'q':iStop=1;break;
            //..... other options
      }
  }
  return 0;
}
void Checking(void)
{
  //test check
}
void Deposit (void)
{
  //find deposit
}

>>In the case statement, do I need to have an option for checking?
you can add
   case 'c': case 'C': Checking(); break;
>>If money is deposited, then the balance has to be incremented
>>and if a check is written, the balance needs to be decreased.
  you can make it:
    balance += deposit; // and if deposit < 0: will be decreased.
                                       //  and if deposit > 0: will be incremented.
>>Would a statement such as balance = balance + amount
Yes,but you can use += operator
And remember, that my code is only sceleton for you programm:
1-st step.
Good luck,Alex
0
cbrookhartAuthor Commented:
I thought I posted this response, but it didn't show up. I am still not able to get this program to run. I'm not understanding all the code needed to put this program together and get it to run. I understand the logic of what the program should do, but I am having problems applying that to C code. This what I have:
#include <stdio.h>
void checking (void);
void deposit (void);
float balance = 0;
int main (void)
{
  int ch,iStop=0;
  while(!iStop)
  {
  printf("Enter D to deposit money, C to write a check, Q to quit.\n");
  printf("\n");
  printf("Your choice:\n");
  ch = getchar()
  switch (ch)
  {
    case 'D' : case 'd':deposit();break;
    case 'C' : case 'c':checking();break;
    case 'Q' : case 'q': iStop = 1;break;
  }
  return 0;
}
void checking(void)
}
void deposit(void)
}
balance += deposit;
return 0;
}

A:\checking.c(18) : error C2143: syntax error : missing ';' before 'switch'
A:\checking.c(26) : error C2143: syntax error : missing ';' before 'type'

Based on what the user selects from the menu, I want to prompt them with a mesage that is appropriate for the selection. If checking is chosen, I want to write a prompt that asks: How much would you like to write a check for?
When the user is done with the checks, I want to have the remaining balance displayed. I also want to test the menu selections so that checks can't be written if there is no balance.
0
AlexVirochovskyCommented:
1.
>>A:\checking.c(18) : error C2143: syntax error : missing ';' before 'switch'
>>A:\checking.c(26) : error C2143: syntax error : missing ';' before 'type'
During copy my code you forget "{":
My code:
>>void Checking(void)
>>{
you code
void Checking(void)
in deposit() you change "{" to "}": it is not same!
2.
>>If checking is chosen, I want to write a prompt that asks:
>>How much would you like to write a check for?
void Checking(void)
{
  char buff[80],float fSummCheck;
  printf("How much would you like to write a check for?\n");
  fgetc(buff);
  fSumm = atof(buff);
  balance += fSumm;
  printf("Balance = %f\n",balance);
}
>>I also want to test the menu selections so that checks
>>can't be written if there is no balance.
Nu, i hope , that this part you can write youself!
Alex
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.