Thanks for the help guys. I have edited the code as follows, but am still getting a compiler error.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char** argv)
{
//Declare our variables
int menuChoice, menuChoice_finished;
int customerType, qwc;
float band;
int Domestic, Commercial;
float bandP1 = 0.20, bandP2 = 0.35, bandP3 = 0.5, bandP4 = 0.75, bandP5 = 2.5; //Multipliers for bands
float freshChargeD; //Calculations for charges to be displayed on bill (Domestic)
float wasteChargeD = qwc*0.25;
float surfChargeD = 10;
float standChargeD = 91 * 0.1;
float totalD = freshChargeD + wasteChargeD + surfChargeD + standChargeD;
float freshChargeC = qwc*bandP5; //Calculations for charges to be displayed on bill (Commercial)
float wasteChargeC = qwc*2.0;
float surfChargeC = 50;
float standChargeC = 91 * 1.30;
float totalCost = freshChargeC + wasteChargeC + surfChargeD + standChargeD, VAT = totalCost * 0.2;
float tc2 = totalCost + VAT;
printf("Hello. Welcome to the program.\n");
printf("Press any key to continue...\n");
getchar();
system("clear");
do
{
printf("Main Menu\n");
printf("-----------\n");
printf("1. Compute and Print the Bill for a Customer\n"); //Menu for user to select what they want to do
printf("2. Show Sums and Statistics\n");
printf("3. Quit the program\n\n");
printf("-----------\n");
scanf("%d", &menuChoice); //Scans and stores users input
}
while (!menuChoice_finished);
switch (menuChoice) //Switch statement for what to do depending on what option is selected by the user
{
case 1:
system("clear");
printf("Enter type of customer (Domestic or Commercial):\n");
scanf("%d", &customerType);
printf("Enter quarterly water consumption total:\n");
scanf("%d", &qwc);
if(qwc >= 1 && qwc <= 5)
{
band = bandP1;
freshChargeD = bandP1 * qwc; //Works out charge depending on band
}
else if(qwc >= 6 && qwc <= 12)
{
band = bandP2;
freshChargeD = ((qwc + 1) - 6) + (bandP1 * 5);
}
else if(qwc >= 13 && qwc <= 25)
{
band = bandP3;
freshChargeD = ((qwc + 1) - 13) + (bandP2 * 7) + (bandP1 * 5);
}
else if(qwc >= 26 && qwc <= 40)
{
band = bandP4;
freshChargeD = ((qwc + 1) - 26) + (bandP3 * 13) + (bandP2 * 7) + (bandP1 * 5);
}
else if(qwc >= 40)
{
band = bandP5;
freshChargeD = (qwc - 40) + (bandP4 * 15) + (bandP3 * 13) + (bandP2 * 7) + (bandP1 * 5);
}
if(customerType == "Domestic") //Bill summary is printed for domestic cust
{
system("clear");
printf("Type of customer: £%d", customerType);
printf("Amount of fresh water consumption: %d", qwc);
printf("Fresh water charges: £%.2f", freshChargeD);
printf("Waste water charges: £%.2f", wasteChargeD);
printf("Surface water charges: £%d", surfChargeD);
printf("Standing charges: £%.2f", standChargeD);
printf("Amount of VAT (if applicable: NA");
printf("Total amount to pay: £%.2f", totalD);
}
else if(customerType == "Commercial") //Bill summary is printed for commercial cust
{
system("clear");
printf("Type of customer: £%d", customerType);
printf("Amount of fresh water consumption: %d", qwc);
printf("Fresh water charges: £%.2f", freshChargeC);
printf("Waste water charges: £%.2f", wasteChargeC);
printf("Surface water charges: £%d", surfChargeC);
printf("Standing charges: £%.2f", standChargeC);
printf("Amount of VAT (if applicable:", VAT);
printf("Total amount to pay: £%.2f", tc2);
}
break;
case 2:
system("clear");
printf("This option is not yet implemented\n\n");
return;
break;
case 3:
printf("Thank you for using this program\n");
menuChoice_finished = 1;
break;
default:
system("clear");
printf("Wrong choice. Please select either 1, 2, or 3.\n");
break;
}
return 0;
}
The error is as follows;
Code:
miniProject1.c: In function ‘main’:
miniProject1.c:82:19: warning: comparison between pointer and integer [enabled by default]
if(customerType == "Domestic") //Bill summary is printed for domestic cust
^
miniProject1.c:94:23: warning: comparison between pointer and integer [enabled by default]
else if(customerType == "Commercial") //Bill summary is printed for commercial cust
It compiles when I remove the else if statements that the above error is part of and the menu choice is now working better than before, but I would still like for the program to display the menu again after displaying the bill or stats after selecting choice 1 or 2. How would I go about implementing this?