Join 300,574 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,193 people online right now. Registration is fast and FREE... Join Now!
/* This program calculates the cost of a house for 15 years */
int main(void) { int initial cost, electric bill, water and sewer, tax rate; total;
printf("\n How much is your house? "); scanf("%d", &initial cost); printf("\n How much is your electric bill? "); scanf("%d", &electric bill); printf("\n How much is your water and sewer? "); scanf("%d", &water and sewer); printf("\n How much is your tax rate? "); scanf("%d", &tax rate);
initial cost = electric bill * water and sewer * taxrate; total = initial cost * HOUSECOST;
printf ("\n Ron A "); printf ("\n Initial Cost = %d", initial cost); printf ("\n Electric Bill = %d", electric bill); printf ("\n Water And Sewer = %d" , water and sewer); printf ("\n Tax Rate = %3.8" , tax rate); printf ("\n Total = %15d" , total); return (0); }
I'm a beginner programmer as well, but don't the variable names have to be one string? So instead of variable name being "water and sewer", shouldn't it be "water_and_sewer" or something like that?
I'm a beginner programmer as well, but don't the variable names have to be one string? So instead of variable name being "water and sewer", shouldn't it be "water_and_sewer" or something like that?
Correct, you cannot have spaces in a variable name.
CODE
int initial cost, electric bill, water and sewer, tax rate; total;
CODE
int initial_cost; int electric_bill; int water_and_sewer; int tax_rate; int total;
QUOTE(revron @ 17 Sep, 2007 - 01:09 PM)
QUOTE(no2pencil @ 17 Sep, 2007 - 01:05 PM)
What is the error(s) that you are getting?
Is the error in processing or compiling?
When I try to compile it.
& What is that error? Can you copy & paste it here?
I'm a beginner programmer as well, but don't the variable names have to be one string? So instead of variable name being "water and sewer", shouldn't it be "water_and_sewer" or something like that?
Correct, you cannot have spaces in a variable name.
CODE
int initial cost, electric bill, water and sewer, tax rate; total;
CODE
int initial_cost; int electric_bill; int water_and_sewer; int tax_rate; int total;
QUOTE(revron @ 17 Sep, 2007 - 01:09 PM)
QUOTE(no2pencil @ 17 Sep, 2007 - 01:05 PM)
What is the error(s) that you are getting?
Is the error in processing or compiling?
When I try to compile it.
& What is that error? Can you copy & paste it here?
Ok, I fixed everything with underscores between the words. But now I get
did you remember to change all the the occurrences?
CODE
#include <stdio.h> #define HOUSECOST 3.8
/* This program calculates the cost of a house for 15 years */
int main() { int initial_cost, electric_bill, water_and sewer, tax_rate; total;
printf("\n How much is your house? "); scanf("%d", &initial_cost); printf("\n How much is your electric bill? "); scanf("%d", &electric_bill); printf("\n How much is your water and sewer? "); scanf("%d", &water_and_sewer); printf("\n How much is your tax rate? "); scanf("%d", &tax_rate);
Ok, I fixed everything with underscores between the words. But now I get
multiple definition of _main error
What IDE are you using to compile your code? (I assume you're using an IDE?) It sounds to me as if you've got multiple source files in one project and its feeding the compiler several different main() functions from your different source files.
did you remember to change all the the occurrences?
CODE
#include <stdio.h> #define HOUSECOST 3.8
/* This program calculates the cost of a house for 15 years */
int main() { int initial_cost, electric_bill, water_and sewer, tax_rate; total;
printf("\n How much is your house? "); scanf("%d", &initial_cost); printf("\n How much is your electric bill? "); scanf("%d", &electric_bill); printf("\n How much is your water and sewer? "); scanf("%d", &water_and_sewer); printf("\n How much is your tax rate? "); scanf("%d", &tax_rate);
printf ("\n Ron A "); printf ("\n Initial Cost = %d", initial_cost); printf ("\n Electric Bill = %d", electric_bill); printf ("\n Water And Sewer = %d" , water_and_sewer); printf ("\n Tax Rate = %3.8" , tax_rate); printf ("\n Total = %15d" , total); return (0); }
If so, can you repost your code?
QUOTE(revron @ 17 Sep, 2007 - 03:32 PM)
QUOTE(NickDMax @ 17 Sep, 2007 - 02:32 PM)
did you remember to change all the the occurrences?
CODE
#include <stdio.h> #define HOUSECOST 3.8
/* This program calculates the cost of a house for 15 years */
int main() { int initial_cost, electric_bill, water_and sewer, tax_rate; total;
printf("\n How much is your house? "); scanf("%d", &initial_cost); printf("\n How much is your electric bill? "); scanf("%d", &electric_bill); printf("\n How much is your water and sewer? "); scanf("%d", &water_and_sewer); printf("\n How much is your tax rate? "); scanf("%d", &tax_rate);
printf ("\n Ron A "); printf ("\n Initial Cost = %d", initial_cost); printf ("\n Electric Bill = %d", electric_bill); printf ("\n Water And Sewer = %d" , water_and_sewer); printf ("\n Tax Rate = %3.8" , tax_rate); printf ("\n Total = %15d" , total); return (0); }
If so, can you repost your code?
Ok, I changed all the occurances and now I get an error that says undeclared indentifier for electric_bill water_and_sewer tax_rate and total. It also says statement has no effect.
/* This program calculates the cost of a house for 15 years */
int main(void) { int initialcost, electricbill, waterandsewer, taxrate,total;
printf("\n How much is your house? "); scanf("%d", &initialcost); printf("\n How much is your electric bill? "); scanf("%d", &electricbill); printf("\n How much is your water and sewer? "); scanf("%d", &waterandsewer); printf("\n How much is your tax rate? "); scanf("%d", &taxrate);
initialcost = electricbill * waterandsewer * taxrate; total = initialcost * HOUSECOST; printf ("\n Ron A "); printf ("\n Initial Cost = %d", initialcost); printf ("\n Electric Bill = %d", electricbill); printf ("\n Water And Sewer = %d" , waterandsewer); printf ("\n Tax Rate = %3.8" , taxrate); printf ("\n Total = %15d\n" , total); system("pause"); return (0); }
QUOTE(revron @ 17 Sep, 2007 - 01:03 PM)
CODE
#include <stdio.h> #define HOUSECOST 3.8
/* This program calculates the cost of a house for 15 years */
int main(void) { int initial cost, electric bill, water and sewer, tax rate; total;
printf("\n How much is your house? "); scanf("%d", &initial cost); printf("\n How much is your electric bill? "); scanf("%d", &electric bill); printf("\n How much is your water and sewer? "); scanf("%d", &water and sewer); printf("\n How much is your tax rate? "); scanf("%d", &tax rate);
initial cost = electric bill * water and sewer * taxrate; total = initial cost * HOUSECOST;
printf ("\n Ron A "); printf ("\n Initial Cost = %d", initial cost); printf ("\n Electric Bill = %d", electric bill); printf ("\n Water And Sewer = %d" , water and sewer); printf ("\n Tax Rate = %3.8" , tax rate); printf ("\n Total = %15d" , total); return (0); }
/* This program calculates the cost of a house for 15 years */
int main(void) { int initialcost, electricbill, waterandsewer, taxrate,total;
printf("\n How much is your house? "); scanf("%d", &initialcost); printf("\n How much is your electric bill? "); scanf("%d", &electricbill); printf("\n How much is your water and sewer? "); scanf("%d", &waterandsewer); printf("\n How much is your tax rate? "); scanf("%d", &taxrate);
initialcost = electricbill * waterandsewer * taxrate; total = initialcost * HOUSECOST; printf ("\n Ron A "); printf ("\n Initial Cost = %d", initialcost); printf ("\n Electric Bill = %d", electricbill); printf ("\n Water And Sewer = %d" , waterandsewer); printf ("\n Tax Rate = %3.8" , taxrate); printf ("\n Total = %15d\n" , total); system("pause"); return (0); }
QUOTE(revron @ 17 Sep, 2007 - 01:03 PM)
CODE
#include <stdio.h> #define HOUSECOST 3.8
/* This program calculates the cost of a house for 15 years */
int main(void) { int initial cost, electric bill, water and sewer, tax rate; total;
printf("\n How much is your house? "); scanf("%d", &initial cost); printf("\n How much is your electric bill? "); scanf("%d", &electric bill); printf("\n How much is your water and sewer? "); scanf("%d", &water and sewer); printf("\n How much is your tax rate? "); scanf("%d", &tax rate);
initial cost = electric bill * water and sewer * taxrate; total = initial cost * HOUSECOST;
printf ("\n Ron A "); printf ("\n Initial Cost = %d", initial cost); printf ("\n Electric Bill = %d", electric bill); printf ("\n Water And Sewer = %d" , water and sewer); printf ("\n Tax Rate = %3.8" , tax rate); printf ("\n Total = %15d" , total); return (0); }
/* This program calculates the cost of a house for 15 years */
int main(void) { int initialcost, electricbill, waterandsewer, taxrate,total;
printf("\n How much is your house? "); scanf("%d", &initialcost); printf("\n How much is your electric bill? "); scanf("%d", &electricbill); printf("\n How much is your water and sewer? "); scanf("%d", &waterandsewer); printf("\n How much is your tax rate? "); scanf("%d", &taxrate);
initialcost = electricbill * waterandsewer * taxrate; total = initialcost * HOUSECOST; printf ("\n Ron A "); printf ("\n Initial Cost = %d", initialcost); printf ("\n Electric Bill = %d", electricbill); printf ("\n Water And Sewer = %d" , waterandsewer); printf ("\n Tax Rate = %3.8" , taxrate); printf ("\n Total = %15d\n" , total); system("pause"); return (0); }
QUOTE(revron @ 17 Sep, 2007 - 01:03 PM)
CODE
#include <stdio.h> #define HOUSECOST 3.8
/* This program calculates the cost of a house for 15 years */
int main(void) { int initial cost, electric bill, water and sewer, tax rate; total;
printf("\n How much is your house? "); scanf("%d", &initial cost); printf("\n How much is your electric bill? "); scanf("%d", &electric bill); printf("\n How much is your water and sewer? "); scanf("%d", &water and sewer); printf("\n How much is your tax rate? "); scanf("%d", &tax rate);
initial cost = electric bill * water and sewer * taxrate; total = initial cost * HOUSECOST;
printf ("\n Ron A "); printf ("\n Initial Cost = %d", initial cost); printf ("\n Electric Bill = %d", electric bill); printf ("\n Water And Sewer = %d" , water and sewer); printf ("\n Tax Rate = %3.8" , tax rate); printf ("\n Total = %15d" , total); return (0); }
MOD EDIT: modified title ~ jayman9
Still have errors such as: undeclared identifier 'cost' undeclared identifier 'electric' statement has no effect syntax error , missing semi colon before 'bill' undeclared identifier 'bill' undeclared identifier 'water' statement has no effect syntax error , missing semi colon before 'and' undeclared identifier 'and' statement has no effect syntax error , missing semi colon before 'sewer' undeclared identifier 'sewer' and so and and so forth with all of the rest of the words
/* This program calculates the cost of a house for 15 years */
int main(void) { int initialcost, electricbill, waterandsewer, taxrate,total;
printf("\n How much is your house? "); scanf("%d", &initialcost); printf("\n How much is your electric bill? "); scanf("%d", &electricbill); printf("\n How much is your water and sewer? "); scanf("%d", &waterandsewer); printf("\n How much is your tax rate? "); scanf("%d", &taxrate);
initialcost = electricbill * waterandsewer * taxrate; total = initialcost * HOUSECOST; printf ("\n Ron A "); printf ("\n Initial Cost = %d", initialcost); printf ("\n Electric Bill = %d", electricbill); printf ("\n Water And Sewer = %d" , waterandsewer); printf ("\n Tax Rate = %3.8" , taxrate); printf ("\n Total = %15d\n" , total); system("pause"); return (0); }
/* This program calculates the cost of a house for 15 years */
int main(void) { int initial cost, electric bill, water and sewer, tax rate; total;
printf("\n How much is your house? "); scanf("%d", &initial cost); printf("\n How much is your electric bill? "); scanf("%d", &electric bill); printf("\n How much is your water and sewer? "); scanf("%d", &water and sewer); printf("\n How much is your tax rate? "); scanf("%d", &tax rate);
initial cost = electric bill * water and sewer * taxrate; total = initial cost * HOUSECOST;
printf ("\n Ron A "); printf ("\n Initial Cost = %d", initial cost); printf ("\n Electric Bill = %d", electric bill); printf ("\n Water And Sewer = %d" , water and sewer); printf ("\n Tax Rate = %3.8" , tax rate); printf ("\n Total = %15d" , total); return (0); }
MOD EDIT: modified title ~ jayman9 [/quote]
Still have errors such as: undeclared identifier 'cost' undeclared identifier 'electric' statement has no effect syntax error , missing semi colon before 'bill' undeclared identifier 'bill' undeclared identifier 'water' statement has no effect syntax error , missing semi colon before 'and' undeclared identifier 'and' statement has no effect syntax error , missing semi colon before 'sewer' undeclared identifier 'sewer' and so and and so forth with all of the rest of the words [/quote]
the corrected code that was posted should compile just fine (this is the first block of code quoted above). the second block of code does not have the corrections in place - there are still whitespaces in the variable names, and the variable total is not declared with a type.
if you copy-paste the first block (the corrected version provided by vijaysnkar) into your file, it will work fine. if you use the second, it won't compile, giving many of the errors you just listed. make sure that you're not creating a new file to hold the corrected code, as this may cause a multiple-definitions error for main().