Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 01-03-2006, 03:04 PM   #1 (permalink)
 
Ultra Techie

Join Date: Jun 2004

Location: Minnesota

Posts: 962

toxicity_27 is on a distinguished road

Send a message via MSN to toxicity_27
Default C++ Errors

Well I'm getting some errors when I'm trying to compile this C++ program. It's really starting to make me mad as the code should be correct. Here is a list of the problems I am getting thanks for the help.

prog12.cpp: In function `int main()':
prog12.cpp:72: error: invalid conversion from `const char*' to `char'
prog12.cpp:89: error: expected primary-expression before "else"
prog12.cpp:89: error: expected `;' before "else"
prog12.cpp:92: error: expected primary-expression before "else"
prog12.cpp:92: error: expected `;' before "else"
prog12.cpp:100: error: ISO C++ forbids comparison between pointer and integer
prog12.cpp:126: error: invalid conversion from `const char*' to `char'
prog12.cpp:160: error: expected `}' at end of input
__________________
Desktop: Core 2 Duo E6600 @ 2.4, Asus P5B-E, 3GB G. Skill DDR2 800, eVGA 8800GT Superclocked 512MB, 22" LG, 19" NEC
Laptop: HP Pavilion dv9500, Core 2 Duo T7300 @ 2.0, 3GB G. Skill DDR2 667, nVidia 8600 M GS 512MB, 17"
toxicity_27 is offline  
Old 01-03-2006, 03:55 PM   #2 (permalink)
 
Monster Techie

Join Date: May 2004

Location: /usr/root/mn/us

Posts: 1,121

bla!! is on a distinguished road

Default

post your code. You have some very simple formatting errors. I'm guessing you missed a semicolon somewhere and it's throwing off the rest of your code.
__________________
<br>
Its a frigging Laptop, not a Labtop!!!!
bla!! is offline  
Old 01-03-2006, 05:00 PM   #3 (permalink)
 
Ultra Techie

Join Date: Jun 2004

Location: Minnesota

Posts: 962

toxicity_27 is on a distinguished road

Send a message via MSN to toxicity_27
Default

#include <iostream>

using namespace std;

//Program Description
//This program will output charges for customers. It will also output
//the total amounts used and total revenue recieved for the amounts.

int main()
{

//Constants
const double water2 = 0.40;
const double water3 = 0.32;
const double electric1 = 0.05;
const double electric2 = 0.03;
const double electric3 = 0.04;
const double electric4 = 0.06;
const double gas1 = 1.50;
const double gas2 = 1.40;
const double gas3 = 1.55;
const double water_minimum = 3.00;
const double electric_minimum = 7.00;
const double gas_minimum = 6.00;

//Variables

int cust_number;
char code;
int water;
int electric;
int gas;
double water_charge;
double electric_charge;
double gas_charge;
double total_bill;
int total_water;
int total_electric;
int total_gas;
double total_water_revenue;
double total_electric_revenue;
double total_gas_revenue;
double total_revenue;
int num_customers;
//Begin Program
//Initialize Totals

num_customers = 0;
total_water = 0;
total_electric = 0;
total_gas = 0;
total_water_revenue = 0;
total_electric_revenue =0;
total_gas_revenue = 0;
//Loop to read, process and report each customer

cout << "Enter Customer Number. 0 ends the input." << endl;
cin >> cust_number;
while (cust_number !=0)
{
cout << "Enter customer code, water used, and electric used.";
cout << endl;
cin >> code >> water >> electric;
if (code = "G")
{
cout << "Enter gas." << endl;
cin >> gas;
//Calculate water charge

if (water <= 10000)
water_charge = water/100*water1;
else if (water <= 100000)
water_charge=100*water1+(water-10000)/100*water2;
else
water_charge=100*water1+900*water2+(water-100000)/100*water3;
//Calculate elctricity charge

if (electric <= 500)
{
electric_charge = electric * electric1;
else

if (electric <= 1500)
electric_charge = 500*electric1+(electric-500)*electric2;
else
electric_charge=500*electric1+1000*electric2+2000* electric3
+(electric-3500)*electric4;
}
if (electric_charge < electric_minimum)
electric_charge = electric_minimum;
//Calculate gas charge
if (code == "G")
{
if (gas <= 50000)
gas_charge = gas/1000*gas1;
else
if (gas <= 100000)
gas_charge = 50*gas1+(gas-50000)/1000*gas2;
else
gas_charge = 50*gas1+50*gas2+(gas-100000)/1000*gas3;
if (gas_charge < gas_minimum)
gas_charge = gas_minimum;
else //code = "R"
gas = 0;
gas_charge = 0;
}
//Calculate total_bill

total_bill = water_charge + electric_charge + gas_charge;
//Report customer bill

cout << "CUSTOMER BILL" << endl;
cout << "Customer Number: " << cust_number << endl;
cout << "Water Used: " << water << endl;
cout << "Water Charge: " << water_charge << endl;
cout << "Electricity Used: " << electric << endl;
cout << "Electricity Charge: " << electric_charge << endl;
if (code = "G")
{
cout << "Gas Used: " << gas << endl;
cout << "Gas Charge: " << gas_charge << endl;
}
cout << "Total Bill: " << total_bill << endl;
//Update summary data

num_customers++;
total_water = total_water + water;
total_electric = total_electric + electric;
total_gas = total_gas + gas;
total_water_revenue = total_water_revenue + electric_charge;
total_gas_revenue = total_gas_revenue + gas_charge;
//Read the next customer number

cout << "Enter next customer number " << endl;
cin >> cust_number;
} //End of looping for each individual customer
//Report summary data for all customers

total_revenue = total_water_revenue + total_electric_revenue +
total_gas_revenue;
cout << "SUMMARY OF CUSTOMERS" << endl;
cout << "Number of Customers: " << num_customers << endl;
cout << "Total Water Used: " << total_water << endl;
cout << "Total Water Revenue: " << total_water_revenue << endl;
cout << "Total Electricity Used: " << total_electric << endl;
cout << "Total Electricity Revenue: " << total_electric_revenue << endl;
cout << "Total Gas Used: " << total_gas << endl;
cout << "Total Gas Revenue: " << total_gas_revenue << endl;
cout << "Total Revenue: " << total_revenue << endl;

return 0;
}
__________________
Desktop: Core 2 Duo E6600 @ 2.4, Asus P5B-E, 3GB G. Skill DDR2 800, eVGA 8800GT Superclocked 512MB, 22" LG, 19" NEC
Laptop: HP Pavilion dv9500, Core 2 Duo T7300 @ 2.0, 3GB G. Skill DDR2 667, nVidia 8600 M GS 512MB, 17"
toxicity_27 is offline  
Old 01-03-2006, 07:00 PM   #4 (permalink)
 
Monster Techie

Join Date: May 2004

Location: /usr/root/mn/us

Posts: 1,121

bla!! is on a distinguished road

Default

You've got quite a few formatting errors in there.

Go back through, thinking of what conditinals you actually want, and then analyze your parenthesis.

Block everything in your IF statements with brackets {}. Even if they're only one liners. I think you're missing quite a few closing brackets and some of your conditional logic is off.
__________________
<br>
Its a frigging Laptop, not a Labtop!!!!
bla!! is offline  
Old 01-04-2006, 02:15 PM   #5 (permalink)
 
Ultra Techie

Join Date: Jun 2004

Location: Minnesota

Posts: 962

toxicity_27 is on a distinguished road

Send a message via MSN to toxicity_27
Default

Can anyone else help me? I just want to get this thing done so I can get it off of my mind.
__________________
Desktop: Core 2 Duo E6600 @ 2.4, Asus P5B-E, 3GB G. Skill DDR2 800, eVGA 8800GT Superclocked 512MB, 22" LG, 19" NEC
Laptop: HP Pavilion dv9500, Core 2 Duo T7300 @ 2.0, 3GB G. Skill DDR2 667, nVidia 8600 M GS 512MB, 17"
toxicity_27 is offline  
Old 01-07-2006, 10:23 AM   #6 (permalink)
 
Newb Techie

Join Date: Aug 2005

Posts: 22

Cache

Default

First off, replace all instances of:

Code:
if (code = "G")
with:
Code:
if (code == 'G')
On line 71, you make a reference to 'water1' which has not been previously declared (it doesn't exist yet).

And the end of the code block for the if statement starting at line 79 is missing it's closing brace.
Cache is offline  
Old 01-08-2006, 01:53 PM   #7 (permalink)
 
Ultra Techie

Join Date: Jun 2004

Location: Minnesota

Posts: 962

toxicity_27 is on a distinguished road

Send a message via MSN to toxicity_27
Default

#include <iostream>

using namespace std;

//Program Description
//This program will output charges for customers. It will also output
//the total amounts used and total revenue recieved for the amounts.

int main()
{

//Constants
const double water1 = 0.60;
const double water2 = 0.40;
const double water3 = 0.32;
const double electric1 = 0.05;
const double electric2 = 0.03;
const double electric3 = 0.04;
const double electric4 = 0.06;
const double gas1 = 1.50;
const double gas2 = 1.40;
const double gas3 = 1.55;
const double water_minimum = 3.00;
const double electric_minimum = 7.00;
const double gas_minimum = 6.00;

//Variables

int cust_number;
char code;
int water;
int electric;
int gas;
double water_charge;
double electric_charge;
double gas_charge;
double total_bill;
int total_water;
int total_electric;
int total_gas;
double total_water_revenue;
double total_electric_revenue;
double total_gas_revenue;
double total_revenue;
int num_customers;
//Begin Program
//Initialize Totals

num_customers = 0;
total_water = 0;
total_electric = 0;
total_gas = 0;
total_water_revenue = 0;
total_electric_revenue =0;
total_gas_revenue = 0;
//Loop to read, process and report each customer

cout << "Enter Customer Number. 0 ends the input." << endl;
cin >> cust_number;
while (cust_number !=0)
{
cout << "Enter customer code, water used, and electric used.";
cout << endl;
cin >> code >> water >> electric;
if (code = "G")
{
cout << "Enter gas." << endl;
cin >> gas;
}
//Calculate water charge

if (water <= 10000)
water_charge = water/100*water1;
else if (water <= 100000)
water_charge=100*water1+(water-10000)/100*water2;
else
water_charge=100*water1+900*water2+(water-100000)/100*water3;
//Calculate electricity charge

if (electric <= 500)
electric_charge = electric * electric1;
else
if (electric <= 1500)
electric_charge = 500*electric1+(electric-500)*electric2;
else
electric_charge=500*electric1+1000*electric2+2000*
electric3
+(electric-3500)*electric4;
if (electric_charge < electric_minimum)
electric_charge = electric_minimum;
//Calculate gas charge
if (code == "G")
{
if (gas <= 50000)
gas_charge = gas/1000*gas1;
else
if (gas <= 100000)
gas_charge = 50*gas1+(gas-50000)/1000*gas2;
else
gas_charge = 50*gas1+50*gas2+(gas-100000)/1000*gas3;
if (gas_charge < gas_minimum)
gas_charge = gas_minimum;
else //code = "R"
gas = 0;
gas_charge = 0;
}
//Calculate total_bill

total_bill = water_charge + electric_charge + gas_charge;
//Report customer bill

cout << "CUSTOMER BILL" << endl;
cout << "Customer Number: " << cust_number << endl;
cout << "Water Used: " << water << endl;
cout << "Water Charge: " << water_charge << endl;
cout << "Electricity Used: " << electric << endl;
cout << "Electricity Charge: " << electric_charge << endl;
if (code == "G")
{
cout << "Gas Used: " << gas << endl;
cout << "Gas Charge: " << gas_charge << endl;
}
cout << "Total Bill: " << total_bill << endl;
//Update summary data

num_customers++;
total_water = total_water + water;
total_electric = total_electric + electric;
total_gas = total_gas + gas;
total_water_revenue = total_water_revenue + electric_charge;
total_gas_revenue = total_gas_revenue + gas_charge;
//Read the next customer number

cout << "Enter next customer number " << endl;
cin >> cust_number;
} //End of looping for each individual customer
//Report summary data for all customers

total_revenue = total_water_revenue + total_electric_revenue +
total_gas_revenue;
cout << "SUMMARY OF CUSTOMERS" << endl;
cout << "Number of Customers: " << num_customers << endl;
cout << "Total Water Used: " << total_water << endl;
cout << "Total Water Revenue: " << total_water_revenue << endl;
cout << "Total Electricity Used: " << total_electric << endl;
cout << "Total Electricity Revenue: " << total_electric_revenue << endl;
cout << "Total Gas Used: " << total_gas << endl;
cout << "Total Gas Revenue: " << total_gas_revenue << endl;
cout << "Total Revenue: " << total_revenue << endl;

return 0;
}

Okay, so I fixed those errors, but now I get these errors*.

prog12.cpp: In function `int main()':
prog12.cpp:72: error: ISO C++ forbids comparison between pointer and integer
prog12.cpp:99: error: ISO C++ forbids comparison between pointer and integer
prog12.cpp:125: error: invalid conversion from `const char*' to `char'


*Note: Line 158 is the very last line.
__________________
Desktop: Core 2 Duo E6600 @ 2.4, Asus P5B-E, 3GB G. Skill DDR2 800, eVGA 8800GT Superclocked 512MB, 22" LG, 19" NEC
Laptop: HP Pavilion dv9500, Core 2 Duo T7300 @ 2.0, 3GB G. Skill DDR2 667, nVidia 8600 M GS 512MB, 17"
toxicity_27 is offline  
Old 01-08-2006, 02:06 PM   #8 (permalink)
 
Newb Techie

Join Date: Aug 2005

Posts: 22

Cache

Default

Hmm, it seems you lack much attention to detail.

I said replace all instances of:

Code:
if (code = "G")
with:
Code:
if (code == 'G')
Note the use of single quotes, not double.
Cache is offline  
Old 01-08-2006, 03:04 PM   #9 (permalink)
 
Ultra Techie

Join Date: Jun 2004

Location: Minnesota

Posts: 962

toxicity_27 is on a distinguished road

Send a message via MSN to toxicity_27
Default

Wow, I'm sorry, I didn't even notice that, yes I must lack attention to detail .
__________________
Desktop: Core 2 Duo E6600 @ 2.4, Asus P5B-E, 3GB G. Skill DDR2 800, eVGA 8800GT Superclocked 512MB, 22" LG, 19" NEC
Laptop: HP Pavilion dv9500, Core 2 Duo T7300 @ 2.0, 3GB G. Skill DDR2 667, nVidia 8600 M GS 512MB, 17"
toxicity_27 is offline  
Old 01-08-2006, 03:06 PM   #10 (permalink)
 
Ultra Techie

Join Date: Jun 2004

Location: Minnesota

Posts: 962

toxicity_27 is on a distinguished road

Send a message via MSN to toxicity_27
Default

Okay, I fixed that, but now I get this error.

prog12.cpp:125: error: invalid conversion from `const char*' to `char'
__________________
Desktop: Core 2 Duo E6600 @ 2.4, Asus P5B-E, 3GB G. Skill DDR2 800, eVGA 8800GT Superclocked 512MB, 22" LG, 19" NEC
Laptop: HP Pavilion dv9500, Core 2 Duo T7300 @ 2.0, 3GB G. Skill DDR2 667, nVidia 8600 M GS 512MB, 17"
toxicity_27 is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On