Skip to main content
For loop fixed, edited to explain issues
Source Link

[Edit] The problem is that when we input values, we get ridiculous figures like 4586368.

#include "stdafx.h" #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <math.h> void main() { int room[20] = {}; int i; int rooms = 0; char option = 0; int lights = 0; int hrsUsed = 0; int Telly = 0; int TVWatt =0; int sumTV; int TVuse = 0; int Computer = 0; int compWatt = 0; int compUsed = 0; int compTotal; int kwH_lights; int fridge = 0; int washLoad = 0; int dryerLoad = 0, dishLoad = 0, cookLoad = 0; int showeruse = 0; int total_kWh; printf("Enter number of rooms"); scanf_s("%d", &rooms); for(i=0;i<rooms;i++) { printf("input average wattage of lights"); scanf_s("%d", &lights); lights=lights/1000; printf("input number of hours use/day (average)"); scanf_s("%d", &hrsUsed); kwH_lights=((lights*hrsUsed)*365); printf("input number of TVs"); scanf_s("%d", &Telly); printf("input average wattage"); scanf_s("%d", &TVWatt); printf("input average use a day"); scanf_s("%d", &TVuse); sumTV=((Telly*(TVWatt/1000))*TVuse)*365; } printf("Input number of fridge/freezer"); scanf_s("%d",&fridge); fridge=(fridge*2)*365; printf("input number of Computers and/or video game consoles in the house"); scanf_s("%d", &Computer); for(i=0;i<Computer;i++) { printf("input wattage"); scanf_s("%d", &compWatt); printf("input average hrs used/day"); scanf_s("%d", &compUsed); compTotal=((compWatt/1000)*compUsed)*365; }  printf("Input average number of washing machine loads /day"); scanf_s("%d",&washLoad); washLoad=washLoad*365; printf("Input average number of clothes dryer loads/day"); scanf_s("%d",&dryerLoad); dryerLoad=(dryerLoad*3)*365; printf("Input average number of dishwasher loads/day"); scanf_s("%d",&dishLoad); dishLoad=(dishLoad*1.5)*365; printf("Input average cooking load/day"); scanf_s("%d",&cookLoad); cookLoad=(cookLoad*7)*365; printf("Input average hrs/day of shower usage"); scanf_s("%d",&showeruse); showeruse=(showeruse*7)*365; total_kWh=((kwH_lights)+(sumTV)+(fridge)+(compTotal)+(dryerLoad)+(dishLoad)+(cookLoad)+(showeruse)); printf("Total= %d", &total_kWh); } 
#include "stdafx.h" #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <math.h> void main() { int room[20] = {}; int i; int rooms = 0; char option = 0; int lights = 0; int hrsUsed = 0; int Telly = 0; int TVWatt =0; int sumTV; int TVuse = 0; int Computer = 0; int compWatt = 0; int compUsed = 0; int compTotal; int kwH_lights; int fridge = 0; int washLoad = 0; int dryerLoad = 0, dishLoad = 0, cookLoad = 0; int showeruse = 0; int total_kWh; printf("Enter number of rooms"); scanf_s("%d", &rooms); for(i=0;i<rooms;i++) { printf("input average wattage of lights"); scanf_s("%d", &lights); lights=lights/1000; printf("input number of hours use/day (average)"); scanf_s("%d", &hrsUsed); kwH_lights=((lights*hrsUsed)*365); printf("input number of TVs"); scanf_s("%d", &Telly); printf("input average wattage"); scanf_s("%d", &TVWatt); printf("input average use a day"); scanf_s("%d", &TVuse); sumTV=((Telly*(TVWatt/1000))*TVuse)*365; } printf("Input number of fridge/freezer"); scanf_s("%d",&fridge); fridge=(fridge*2)*365; printf("input number of Computers and/or video game consoles in the house"); scanf_s("%d", &Computer); for(i=0;i<Computer;i++) printf("input wattage"); scanf_s("%d", &compWatt); printf("input average hrs used/day"); scanf_s("%d", &compUsed); compTotal=((compWatt/1000)*compUsed)*365; printf("Input average number of washing machine loads /day"); scanf_s("%d",&washLoad); washLoad=washLoad*365; printf("Input average number of clothes dryer loads/day"); scanf_s("%d",&dryerLoad); dryerLoad=(dryerLoad*3)*365; printf("Input average number of dishwasher loads/day"); scanf_s("%d",&dishLoad); dishLoad=(dishLoad*1.5)*365; printf("Input average cooking load/day"); scanf_s("%d",&cookLoad); cookLoad=(cookLoad*7)*365; printf("Input average hrs/day of shower usage"); scanf_s("%d",&showeruse); showeruse=(showeruse*7)*365; total_kWh=((kwH_lights)+(sumTV)+(fridge)+(compTotal)+(dryerLoad)+(dishLoad)+(cookLoad)+(showeruse)); printf("Total= %d", &total_kWh); } 

[Edit] The problem is that when we input values, we get ridiculous figures like 4586368.

#include "stdafx.h" #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <math.h> void main() { int room[20] = {}; int i; int rooms = 0; char option = 0; int lights = 0; int hrsUsed = 0; int Telly = 0; int TVWatt =0; int sumTV; int TVuse = 0; int Computer = 0; int compWatt = 0; int compUsed = 0; int compTotal; int kwH_lights; int fridge = 0; int washLoad = 0; int dryerLoad = 0, dishLoad = 0, cookLoad = 0; int showeruse = 0; int total_kWh; printf("Enter number of rooms"); scanf_s("%d", &rooms); for(i=0;i<rooms;i++) { printf("input average wattage of lights"); scanf_s("%d", &lights); lights=lights/1000; printf("input number of hours use/day (average)"); scanf_s("%d", &hrsUsed); kwH_lights=((lights*hrsUsed)*365); printf("input number of TVs"); scanf_s("%d", &Telly); printf("input average wattage"); scanf_s("%d", &TVWatt); printf("input average use a day"); scanf_s("%d", &TVuse); sumTV=((Telly*(TVWatt/1000))*TVuse)*365; } printf("Input number of fridge/freezer"); scanf_s("%d",&fridge); fridge=(fridge*2)*365; printf("input number of Computers and/or video game consoles in the house"); scanf_s("%d", &Computer); for(i=0;i<Computer;i++) { printf("input wattage"); scanf_s("%d", &compWatt); printf("input average hrs used/day"); scanf_s("%d", &compUsed); compTotal=((compWatt/1000)*compUsed)*365; }  printf("Input average number of washing machine loads /day"); scanf_s("%d",&washLoad); washLoad=washLoad*365; printf("Input average number of clothes dryer loads/day"); scanf_s("%d",&dryerLoad); dryerLoad=(dryerLoad*3)*365; printf("Input average number of dishwasher loads/day"); scanf_s("%d",&dishLoad); dishLoad=(dishLoad*1.5)*365; printf("Input average cooking load/day"); scanf_s("%d",&cookLoad); cookLoad=(cookLoad*7)*365; printf("Input average hrs/day of shower usage"); scanf_s("%d",&showeruse); showeruse=(showeruse*7)*365; total_kWh=((kwH_lights)+(sumTV)+(fridge)+(compTotal)+(dryerLoad)+(dishLoad)+(cookLoad)+(showeruse)); printf("Total= %d", &total_kWh); } 
Source Link

Problems with a program [C arrays]

My friend and I are trying to build a program together, but it just doesn't seem to be working. Neither of us have much experience with C, so we just can't spot the issue... Any advice or help would be much appreciated! Apologies for the slightly awkward lyrics?

#include "stdafx.h" #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <math.h> void main() { int room[20] = {}; int i; int rooms = 0; char option = 0; int lights = 0; int hrsUsed = 0; int Telly = 0; int TVWatt =0; int sumTV; int TVuse = 0; int Computer = 0; int compWatt = 0; int compUsed = 0; int compTotal; int kwH_lights; int fridge = 0; int washLoad = 0; int dryerLoad = 0, dishLoad = 0, cookLoad = 0; int showeruse = 0; int total_kWh; printf("Enter number of rooms"); scanf_s("%d", &rooms); for(i=0;i<rooms;i++) { printf("input average wattage of lights"); scanf_s("%d", &lights); lights=lights/1000; printf("input number of hours use/day (average)"); scanf_s("%d", &hrsUsed); kwH_lights=((lights*hrsUsed)*365); printf("input number of TVs"); scanf_s("%d", &Telly); printf("input average wattage"); scanf_s("%d", &TVWatt); printf("input average use a day"); scanf_s("%d", &TVuse); sumTV=((Telly*(TVWatt/1000))*TVuse)*365; } printf("Input number of fridge/freezer"); scanf_s("%d",&fridge); fridge=(fridge*2)*365; printf("input number of Computers and/or video game consoles in the house"); scanf_s("%d", &Computer); for(i=0;i<Computer;i++) printf("input wattage"); scanf_s("%d", &compWatt); printf("input average hrs used/day"); scanf_s("%d", &compUsed); compTotal=((compWatt/1000)*compUsed)*365; printf("Input average number of washing machine loads /day"); scanf_s("%d",&washLoad); washLoad=washLoad*365; printf("Input average number of clothes dryer loads/day"); scanf_s("%d",&dryerLoad); dryerLoad=(dryerLoad*3)*365; printf("Input average number of dishwasher loads/day"); scanf_s("%d",&dishLoad); dishLoad=(dishLoad*1.5)*365; printf("Input average cooking load/day"); scanf_s("%d",&cookLoad); cookLoad=(cookLoad*7)*365; printf("Input average hrs/day of shower usage"); scanf_s("%d",&showeruse); showeruse=(showeruse*7)*365; total_kWh=((kwH_lights)+(sumTV)+(fridge)+(compTotal)+(dryerLoad)+(dishLoad)+(cookLoad)+(showeruse)); printf("Total= %d", &total_kWh); }