Thread: Could somebody please help me with this C program

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    7
    Sorry about the look of my previous code, but my friend and I actually are working on a new version, this is what we have so far

    Code:
    #include<stdio.h>
    
    void printr(float,float,float,float, float, float, float, char, char, char);
    void main(void)
    {
    
    float b1,b2,b3, bal, tran, with, dep, bill, amount;
    char junk, ans;
    char date[15],withdate, depdate, billdate;
    printf("Please type the last balance as float\n");
    scanf("%f", &bal);
    scanf("%c",&junk);
    printf("Transactions\n");
    printf("Please type Y to continue or N if you want to stop\n");
    scanf("%c", &ans);
    while(ans=='Y')
    	{	
    		printf("Please type the date as one string\n");
    		scanf("%s", &date);	    		
    		printf("Next type transtype as integer and amount as float\n");
    		scanf("%d%f", &tran, &amount);
    		
    			if(tran=1)
    				{
    					bal=bal-amount;
    					with=amount;
    					withdate=date;
    				}
    			else if(tran=2)
    				{
    					bal=bal+amount;
    					dep=amount;
    					depdate=date;	 	 	 	 
    				}
    			else
    				{
    					billdate=date;
    					bal-=amount;
    					bill=amount;
    				}
    scanf("%c",&junk);
    printf("Please type Y to continue or N if you want to stop\n");
    scanf("%c", &ans);	
    	}
    b3=bal;
    b2=b1+dep;
    b1=6000-with;
    
    printr(with, dep, bill, bal, b3, b2, b1, withdate[15], depdate[15], billdate[15]); 
    }
    void printr(float with, float dep, float bill, float bal, float b3, float b2, float b1, char withdate[], char depdate[], char billdate[])
    {
    printf("Date \t type \t amount \t balance\n");
    printf("%c \t wd \t %f \t %f\n", withdate, with, b1);
    printf("%c \t wd \t %f \t %f\n", depdate, dep, b2);
    printf("%c \t wd \t %f \t %f\n", billdate, bill, b3);
    }
    but once again I get some of the same errors i got last time and i really don't see what they are talking about. These are the new errors, a little less than before

    "1a22.c", line 27: left operand must be modifiable lvalue: op "="
    "1a22.c", line 33: left operand must be modifiable lvalue: op "="
    "1a22.c", line 37: left operand must be modifiable lvalue: op "="
    "1a22.c", line 49: warning: improper pointer/integer combination: arg #8
    "1a22.c", line 49: warning: improper pointer/integer combination: arg #9
    "1a22.c", line 49: warning: improper pointer/integer combination: arg #10
    "1a22.c", line 52: identifier redeclared: printr
    current : function(float, float, float, float, float, float, float, pointer to char, pointer to char, pointer to char) returning void
    previous: function(float, float, float, float, float, float, float, char, char, char) returning void : "1a22.c", line 3
    cc: acomp failed for 1a22.c

  2. #2
    CS Author and Instructor
    Join Date
    Sep 2002
    Posts
    511
    Code:
    scanf("%d%f", &tran, &amount);
    		
    			if(tran=1)
    				{
    					bal=bal-amount;
    					with=amount;
    					withdate=date;
    				}
    			else if(tran=2)
    				{
    					bal=bal+amount;
    					dep=amount;
    					depdate=date;	 	 	 	 
    				}
    			else
    				{
    					billdate=date;
    					bal-=amount;
    					bill=amount;
    				}
    You if look like they should be testing for equality not assignment (== vs. =)

    if (tran == 1)
    {

    }
    else if (tran == 2)
    {

    }

    That looks like one problem...
    Mr. C: Author and Instructor

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM