c - Can't nail the problems with this code -
ok got thing going here. keep getting few errors.
#define _crt_secure_no_warnings #include <stdio.h> #include <stdlib.h> #include <cstdio> //functions called int get_lmt(); int get_total_trash(); void print_output(int, int); //why void? int main(void) { char hauler[100]; int t_trash=0, lmt=0; printf("hello \n name: "); fflush(stdin); scanf("%s", &hauler); t_trash = get_total_trash(); lmt = get_lmt(); printf("name: %s\n", &hauler); print_output(lmt, t_trash); system("pause"); return 0; } int get_total_trash() { char yn = 'y'; int t_trash = 0, trash=0; while (yn != 'n') { printf("what trash: "); fflush(stdin); scanf("%i", &trash); t_trash = trash + t_trash; printf("do have more trash tons? (y or n): "); fflush(stdin); scanf("%c", &yn); } return t_trash; } int get_lmt() { int lmt = 0; printf("what last months trash: "); fflush(stdin); scanf("%i", &lmt); return lmt; } void print_output(int lmt, int t_trash) { float rate = 350.00, charge; int sum=0, total=0; if (lmt > t_trash) { printf("total trash tons: %i\n", &t_trash); printf("last month's trash: %i\n", &lmt); printf("rate: $ %.2f\n", &rate); } else { printf("what tonnage rate: "); fflush(stdin); scanf("%.2f\n", &charge); sum = t_trash - lmt; total = sum * charge; rate = rate + total; printf("total trash tons: %i\n", &t_trash); printf("last month's trash: %i\n", &lmt); printf("rate: $ %.2f\n", &rate); } }
now should doing is, main should calling functions on screen needed. did of cout cin , works fine no problems. when run (this modified printf , scanf) says:
ok update: got ton of work. 1 more thing , should good. outcome not go expected.
instead of output of last months trash: 100 (asked @ end of loop) trash tonnage: 50 (accumulated in loop) rate: 350.00 (float variable)
(this if last month trash > month.)
i bad numbers around. makes no mathematical sense. other works fine. code the last function wrong guys?
lots of problems code. lots of them.
1) print_output defintiion takes in char[100] (char*), print_output declatation takes char
2) when pass hauler print_output, passing in hauler[100] (a char, , 1 pass end of array boot)
3) printf("name: %s\n", &hauler); hauler of type char[100] (char*), &hauler char**.
there more.
Comments
Post a Comment