Hey guys,
I was wondering if you could hep me. I'm a first yeat University student and i was having some problems. Here's my (amateur) program:
Code:
#include <stdio.h>
#define CHARGE 40
main()
{
char ownerName[81];
int apartmentNumber;
int bedrooms;
char category;
int levy;
char message [81]="";
double totalLevyPayable;
printf("\nPlease enter your name: ");
gets(ownerName);
printf("\nPlease enter your apartment number: ");
scanf("%d", &apartmentNumber);
printf("\nPlease enter the amount of bedrooms your apartment has: ");
scanf("%d", &bedrooms);
printf("\nPlease enter the category of the apartment(A, B or C): ");
getchar();
category=getchar();
switch(category)
{
case 'a':
case 'A': if (bedrooms <= 1)
levy = (10);
else if (bedrooms = 2)
levy = (10 + 3);
else
levy = (10 + 3 + 3) * (bedrooms - 2);
break;
case 'b':
case 'B': if (bedrooms <= 2)
levy = (7 + 1);
else
levy = (7 + 1 + 2) * (bedrooms - 1);
break;
case 'c':
case 'C': levy = 5 + (bedrooms * 1);
break;
default : strcpy(message, "\nInvalid category.");
break;
}
if(strcmp(message,"")==0)
{
totalLevyPayable = (levy * CHARGE);
printf("\n E V E R R I S E E S T A T E ");
printf("\n Northern Paradise Beach ");
printf("\n\n%s", ownerName);
printf("\nApartment number: %d", apartmentNumber);
printf("\nEver Rise Estate");
printf("\n--------------------------------------------------------");
printf("\nParticulars of your apartment number %d:\n", apartmentNumber);
printf("\nCategory : %s", &category);
printf("\nNumber of Bedrooms : %d", bedrooms);
printf("\nLevy (in units) : %d", levy);
printf("\nCharge per unit : 40.00");
printf("\n\nTotal Levy payable %7.2lf", totalLevyPayable);
printf("\n-------------------------------------------------------\n");
}
else printf("\n%s\n", message);
}
My first problem is mt first case category:
Code:
case 'a':
case 'A': if (bedrooms <= 1)
levy = (10);
else if (bedrooms = 2)
levy = (10 + 3);
else
levy = (10 + 3 + 3) * (bedrooms - 2);
break;
This doesn't seem to work for some reason. If you enter 1 or 2 bedrooms it doeswork but as soon as you go over 2 bedrooms and have a category A it doesnt. Can anyone help me with this?
Another line causing problems with me is this one:
printf("\nCategory : %s", &category);
This prints out the character right but the character is usually followed by a smile or something else.Can you help me with this? And also could i also turn this charcter into an uppercase one automatically.
And finally, (if your still with me) id like some help with doing a loop that ask users whether they want to re-enter the information and if they type yes the screen would be cleared and the program would start again.
Any help would be greatly appreciated.
Thnx in adavance guys!