You are viewing our Forum Archives. To view or take place in current topics click here.
Help with C programming please?
Posted:
Help with C programming please?Posted:
Status: Offline
Joined: Jun 22, 201113Year Member
Posts: 199
Reputation Power: 7
Status: Offline
Joined: Jun 22, 201113Year Member
Posts: 199
Reputation Power: 7
/*
program: proj3
Name: Jordan Ward
Email: jw363912 @ ohio.edu
Description: This program reads the number of months for which
a resident is being billed and how mcuh water was
used for that many months.
Date: Date you finish.
*/
#include <stdio.h>
double sewer_and_water_charge(int gal, double wrate);
/*
pre int gal and double wrate contains the
gallons and sewer and water charge entered
by the user
post sewer and water charge is returned
*/
double garbage_charge(double grate, int mon);
/*
pre double grate and int mon contains the
garbage rate and number or months entered
by the user
post garbage charge is returned
*/
int main(void)
{
int gallons;
int months; /* user input - number of gallons and months */
double wrate;
double grate;
double total; /* output - calculated values */
printf("\tEnter the number of months: ");
scanf("%d", &months);
if(months != 1 && months != 2 && months != 3) /* input validation for number of months */
{
printf("\tInvalid number of months. Enter 1, 2, or 3: ");
scanf("%d", &months);
}
printf("\tEnter the number of gallons used for %d months: ", months);
scanf("%d", &gallons);
printf("\n\n\tNumber of months %6d", months);
printf("\n\tGallons used %6d", gallons);
wrate = sewer_and_water_charge(gallons, wrate); /* call to the function sewer */
printf("\n\n\tSewer and water charge $%5.2lf", wrate);
grate = garbage_charge(grate, months); /* call to the function garbage */
printf("\n\tGarbage charge $%5.2lf", grate);
total = wrate + grate;
printf("\n\n\tTotal bill $%6.2lf", total);
getch();
return 0;
}
double sewer_and_water_charge(int gal, double wrate)
{
if(gal < 1000) /* first range */
wrate = gal * 0.03;
else if(gal <= 2000) /* second range */
wrate = (gal - 1000) * 0.05 + 30;
else if(gal > 2000) /* third range */
wrate = (gal - 2000) * 0.08 + 80;
return(wrate);
}
double garbage_charge(double grate, int months)
{
grate = 7.50 * months;
return(grate);
}
My program runs and has all the correct calculations in Dev-C++ but when I put it into the compiler(PuTTY) that I have to use for the class that this assignment is for and I type gcc -Wall assign3.c to compile it, it says that double wrate and double grate are uninitialized in function main, why is this? Thanks!
#2. Posted:
Status: Offline
Joined: Jun 22, 201113Year Member
Posts: 199
Reputation Power: 7
Status: Offline
Joined: Jun 22, 201113Year Member
Posts: 199
Reputation Power: 7
someone pleaseeeeeeeeeeeee help
- 0useful
- 0not useful
#3. Posted:
Status: Offline
Joined: Sep 06, 201014Year Member
Posts: 1,069
Reputation Power: 47
Status: Offline
Joined: Sep 06, 201014Year Member
Posts: 1,069
Reputation Power: 47
Why are you passing wrate and grate into the two functions that you are using to set them? Try not doing that and see if that works.
- 0useful
- 0not useful
#4. Posted:
Status: Offline
Joined: Aug 14, 200915Year Member
Posts: 1,291
Reputation Power: 65
Status: Offline
Joined: Aug 14, 200915Year Member
Posts: 1,291
Reputation Power: 65
M0D1F13D wrote Why are you passing wrate and grate into the two functions that you are using to set them? Try not doing that and see if that works.
If he made them pointers then it would be fine, they'd just be out values.
- 0useful
- 0not useful
You are viewing our Forum Archives. To view or take place in current topics click here.