Hey guys. First off-I'm a new'b---so bare with me here :)
I am in school for web design and this is my first programming course ever. It's all in C++ and I have been doing really well in the class but I am stumped on my project due next week. I just received it today and before I even start punching in code I had a couple questions. (I am sure I will be asking for more help later so here's the project)----
CIS126 Final Project
Landscape Company Program
A carpenter needs a program that computes the price of any desk a customer orders based on the following input fields: order number, desk length in inches and width in inches, type of wood, and number of drawers.
The price is computed as follows:
a. The charge for all desks is a minimum $200
b. If the surface (l x w) is over 750 square inches, add $50.
c. If the wood is "mahogany" add $150; for "oak" add $125. There is no extra
charge for "pine".
d. For every drawer in the desk, there is an additional $30 charge.
This program should prompt the user to enter the data, compute the charges and
display them back to the user.
---So my first question is about values.
would the types of wood asked to be displayed for the program be strings in the int/var/float/char/string section? i.e
main ()
{
string oak=150?
-----------
all i am really confident right now is
printf/scanf functions such as
printf("please input your order number\n\n");
scanf(" %d &ordernumber",);
(or is that even right?) sorry if this is a little confusing to get my point accross I'm sleep deprived and already freaking out about the project. Would appreciate all the help I could get!
-THNKS
Project for school.
Started by unbrknchane, Feb 16 2010 05:29 AM
11 replies to this topic
#1
Posted 16 February 2010 - 05:29 AM
|
|
|
#2
Posted 16 February 2010 - 05:42 AM
I'll help you but just a question. how do i get the number of inshes from L X and Y ?
Just give me the math equasion..
Just give me the math equasion..
#3
Posted 16 February 2010 - 06:21 AM
The problem with these types of assignments, is people start them without thinking about what support functions are needed.
This is how I would code it. I seperate the input/output code from the application logic ("business logic").
Business logic - Wikipedia, the free encyclopedia
The input/ouput code gives a message and requests a integer. It then does basic validation, ie: checks for invalid ints and range checking.
Once you have a simple function that handles input/output, the coding is simple. btw, I have deliberately written this using poor variable naming and one line logic just in case you try to submit this as your own. It will cause some questions from your teachers, so dont!
This is how I would code it. I seperate the input/output code from the application logic ("business logic").
Business logic - Wikipedia, the free encyclopedia
The input/ouput code gives a message and requests a integer. It then does basic validation, ie: checks for invalid ints and range checking.
Once you have a simple function that handles input/output, the coding is simple. btw, I have deliberately written this using poor variable naming and one line logic just in case you try to submit this as your own. It will cause some questions from your teachers, so dont!
#include <stdio.h>
#include <stdlib.h>
int in(char* msg, int* result, int min, int max)
{
for (;;) {
char s[256];
printf("> %s [%d-%d] : ", msg, min, max);
if (!fgets(s, sizeof(s), stdin)) return 0;
if (sscanf(s, "%d", result) != 1) return 0;
if (*result >= min && *result <= max) return 1;
puts("ERROR# Value is Out Of Range. Please Re-Enter.");
}
return 1;
}
int main(int argc, char* argv[])
{
int o, w, h, t, d;
do {
puts("Landscape Company Program\n");
while (
in("Order #", &o, 1, 1000) &&
in("Width (inches)", &w, 1, 100000) &&
in("Height (inches)", &h, 1, 100000) &&
in("Wood Type (1=Mahogany, 2=Oak, 3=Pine)", &t, 1, 3) &&
in("# of Drawers", &d, 1, 50))
{
printf("\nCharge=$%d\n\n", 100+(w*h>750?50:0)+(t==1?150:t==2?125:0)+(d*50));
}
while (!in("Do you want to exit? (1=yes, 2=no)", &o, 1, 2));
} while (o != 1);
return 0;
}
Buzz PHP Class Library - Web Components Made Easy!
http://www.buzzphp.com/
http://www.buzzphp.com/
#4
Posted 16 February 2010 - 08:04 AM
lol. no i wouldnt do that anyway--
funny you mentioned that though b/c i was looking the code and i got my answer but was wondering how that program would ever run
:thumbup:
thanks guys! i think i can handle it from here, but i'll check back if i get stumped again.
(sure i'll be reading and writing posts on here for a long time to come) :)
funny you mentioned that though b/c i was looking the code and i got my answer but was wondering how that program would ever run
:thumbup:
thanks guys! i think i can handle it from here, but i'll check back if i get stumped again.
(sure i'll be reading and writing posts on here for a long time to come) :)
#5
Posted 18 February 2010 - 06:26 AM
ok...here's what i've got so far guys. im totally stumped :(
/*
PRG:FINAL PROJECT
DESCRPITION: DESK ORDER PRG.
*/
#include <stdio.h>
#include <stdlib.h>
main();
float area=0.0;
float baseprice=200.00;
float drawers=0.0;
float drawercost=0.0;
float subtotal=0.0;
float base
int min;
int max;
{
for (;;) ;
char s[256];
printf("> %s [%d-%d] : ", msg, min, max);
if (!fgets(s, sizeof(s), stdin));
scanf(s, "%d", result) != 1);
if (*result >= min && *result <= max)
printf("ERROR# Value is Out Of Range. Please Re-Enter.");
}
return 0;
int main;
int argc;
char* argv[];
{
int o=OrderNumber;
int w=Width;
int h=Height;
int d=NumberofDrawers;
int t=WoodType;
printf("Landscape Company Program\n\n");
printf("Please enter order number\n\n");
scanf("%d," &o);
printf("Please enter width\n\n;
scanf("%f," &w);
printf"Please enter height\n\n");
scanf("%f",&h);
printf("Please enter the NumberofDrawers\n\n);
scanf("%d", &d);
printf("Please enter WoodType\n\n");
scanf ("%s", %t);
{
in("Order #", &o, 1, 1000) &&
in("Width (inches)", &w 1, 100000))&&
in("Height (inches)", &h1, 100000) &&
in("WoodType (1=Mahogany, 2=Oak, 3=Pine)", &t, 1, 3) &&
in("# of Drawers", &d, 1, 50))
}
printf("\nCharge=$%d\n\n", 100+(w*h>750?50:0)+(t==1?150:t==2?125:0)+(d*50));
while
{
(!in("Do you want to exit? (1=yes, 2=no)", &o, 1, 2));
}
while
{
(o != 1);
}
return 0;
}
Edited by WingedPanther, 26 February 2010 - 09:16 AM.
add code tags (the # button)
#6
Posted 18 February 2010 - 06:29 AM
:cursing:
as you can see im pretty stumped here.
are my variables looking like they would turn out legit
also--should i do if else statements as wells as set some default messages in case of enduser errors?
all help will be greatly appreciated
as you can see im pretty stumped here.
are my variables looking like they would turn out legit
also--should i do if else statements as wells as set some default messages in case of enduser errors?
all help will be greatly appreciated
#7
Posted 18 February 2010 - 07:12 AM
Try using code tags whenever you post code in the future.
I'm a little confused you said this class was c++ yet you're using only C as far as I can tell. This is your final project?
My gcc output.
/*
PRG:FINAL PROJECT
DESCRPITION: DESK ORDER PRG.
*/
#include <stdio.h>
#include <stdlib.h>
main();
float area=0.0;
float baseprice=200.00;
float drawers=0.0;
float drawercost=0.0;
float subtotal=0.0;
float base
int min;
int max;
{
for (; ;
char s[256];
printf("> %s [%d-%d] : ", msg, min, max);
if (!fgets(s, sizeof(s), stdin));
scanf(s, "%d", result) != 1);
if (*result >= min && *result <= max)
printf("ERROR# Value is Out Of Range. Please Re-Enter.");
}
return 0;
int main;
int argc;
char* argv[];
{
int o=OrderNumber;
int w=Width;
int h=Height;
int d=NumberofDrawers;
int t=WoodType;
printf("Landscape Company Program\n\n");
printf("Please enter order number\n\n");
scanf("%d," &o);
printf("Please enter width\n\n;
scanf("%f," &w);
printf"Please enter height\n\n");
scanf("%f",&h);
printf("Please enter the NumberofDrawers\n\n);
scanf("%d", &d);
printf("Please enter WoodType\n\n");
scanf ("%s", %t);
{
in("Order #", &o, 1, 1000) &&
in("Width (inches)", &w 1, 100000))&&
in("Height (inches)", &h1, 100000) &&
in("WoodType (1=Mahogany, 2=Oak, 3=Pine)", &t, 1, 3) &&
in("# of Drawers", &d, 1, 50))
}
printf("\nCharge=$%d\n\n", 100+(w*h>750?50:0)+(t==1?150:t==2?125:0)+(d*50));
while
{
(!in("Do you want to exit? (1=yes, 2=no)", &o, 1, 2));
}
while
{
(o != 1);
}
return 0;
}
I'm a little confused you said this class was c++ yet you're using only C as far as I can tell. This is your final project?
My gcc output.
$ gcc -o test2 test2.c
test2.c:25: warning: data definition has no type or storage class
test2.c:34: error: expected `=', `,', `;', `asm' or `__attribute__' before `int'
test2.c:36: error: expected identifier or `(' before `{' token
test2.c:46: error: expected identifier or `(' before `return'
test2.c:47: error: `main' redeclared as different kind of symbol
test2.c:25: error: previous declaration of `main' was here
test2.c:50: error: expected identifier or `(' before `{' token
test2.c:61:8: warning: missing terminating " character
test2.c:61: error: missing terminating " character
test2.c:65:8: warning: missing terminating " character
test2.c:65: error: missing terminating " character
#8
Posted 18 February 2010 - 08:38 AM
well its a class programming in 'C' but we also do C++ and a little bit of Java. The basis is 'C' though. I am in school for web development and this is my first programming class. This project is in 'C' though. Here's what i've gone with to start the program. I am using all floats instead of int for multiplication purposes and i've added some comments. what would you do from here?
#include <headerfile.h>
#include <stdio.h>
#include <stdlib.h>
main ()
{
char begin;
float basePrice=200.00;
float length=0.0;
float width=0.0;
float area=0.0;
char woodtype;
float drawers=0.0;
float drawerCost=0.0;
float subtotal=0.0;
printf("would you like to purchase a desk (y)es or (n)o");
scanf(" %c", &begin);
if (begin=='n')
{
printf("please reconsider a desk in the future\n");
return 0;
}
else if (begin!='y')
{
printf("I am sorry that is not a valid answer.\n");
return 0;
}
else
{
//ask for wood type and test
//ask for size and test
//ask for drawers and test
//tabulate and show price
}
return 0;
}
//im getting an illegal escape sequence on my last line and one other error in syntax
#include <headerfile.h>
#include <stdio.h>
#include <stdlib.h>
main ()
{
char begin;
float basePrice=200.00;
float length=0.0;
float width=0.0;
float area=0.0;
char woodtype;
float drawers=0.0;
float drawerCost=0.0;
float subtotal=0.0;
printf("would you like to purchase a desk (y)es or (n)o");
scanf(" %c", &begin);
if (begin=='n')
{
printf("please reconsider a desk in the future\n");
return 0;
}
else if (begin!='y')
{
printf("I am sorry that is not a valid answer.\n");
return 0;
}
else
{
//ask for wood type and test
//ask for size and test
//ask for drawers and test
//tabulate and show price
}
return 0;
}
//im getting an illegal escape sequence on my last line and one other error in syntax
#9
Posted 18 February 2010 - 08:41 AM
here's what i have for woodtype width, height, etc:
printf("Landscape Company Program\n\n");
printf("Please enter order number\n\n");
scanf("%d," &o);
printf("Please enter width\n\n");
scanf("%f," &w);
printf"Please enter height\n\n");
scanf("%f",&h);
printf("Please enter the NumberofDrawers\n\n");
scanf("%d", &d);
printf("Please enter WoodType in number value (1=Mahogany, 2=Oak, 3=Pine))\n\n");
scanf ("%s", %t);
printf("\nCharge=$%d\n\n", 100+(w*h>750?50:0)+(t==1?150:t==2?125:0)+(d*50));
while
(!in("Do you want to exit? (1=yes, 2=no)", &o, 1, 2));
while
(o != 1);
// any assistance to help me piece this clusterf*** together would be GREATLY appreciated!!!! :thumbup:
printf("Landscape Company Program\n\n");
printf("Please enter order number\n\n");
scanf("%d," &o);
printf("Please enter width\n\n");
scanf("%f," &w);
printf"Please enter height\n\n");
scanf("%f",&h);
printf("Please enter the NumberofDrawers\n\n");
scanf("%d", &d);
printf("Please enter WoodType in number value (1=Mahogany, 2=Oak, 3=Pine))\n\n");
scanf ("%s", %t);
printf("\nCharge=$%d\n\n", 100+(w*h>750?50:0)+(t==1?150:t==2?125:0)+(d*50));
while
(!in("Do you want to exit? (1=yes, 2=no)", &o, 1, 2));
while
(o != 1);
// any assistance to help me piece this clusterf*** together would be GREATLY appreciated!!!! :thumbup:
#10
Posted 18 February 2010 - 08:52 AM
Are you stuck using scanf for input, and the instructor hasn't mentioned the issues involved with obtaining user input using it? And do wrap your code in code tags.
#11
Posted 18 February 2010 - 11:44 AM
Ha, thats funny. You have half of my code and half of you own code in the one file!
Didn't you just try to compile my original post to see that it actually works without being changed?
Didn't you just try to compile my original post to see that it actually works without being changed?
Buzz PHP Class Library - Web Components Made Easy!
http://www.buzzphp.com/
http://www.buzzphp.com/
#12
Posted 18 February 2010 - 12:03 PM
Your skeleton code compilies here. What compilier are you using?
Just for fun, I compilied my original code for the Commodore 64. I had to change the input buffer size to something smaller and change the ranges because and int on cc65 is 16bit.
[ATTACH]2533[/ATTACH]
I dont know. Its a bit of fun :w00t:
Just for fun, I compilied my original code for the Commodore 64. I had to change the input buffer size to something smaller and change the ranges because and int on cc65 is 16bit.
[ATTACH]2533[/ATTACH]
I dont know. Its a bit of fun :w00t:
Attached Files
Buzz PHP Class Library - Web Components Made Easy!
http://www.buzzphp.com/
http://www.buzzphp.com/


Sign In
Create Account

Back to top











