Hey there, I'm kinda new to Programing and I'm still learning the basics, I have Borland C++ 5.5 program and I need to write the following program in it, any help about it would be very appreciated, please reply ASAP :)

The Program is the following:

Write a program to determine whether a series of purchases come in over or under a budget. The program starts by reading a budget and a sales tax rate. It then reads a series of input lines containing the price of an item, the number purchased, and a discount rate. The program computes and prints the cost of each item. After reading all the input, it then prints the total cost and how it compared to the budget.

A run of the program:


Enter your budget $: 25.00

How many items are you buying? 4

Enter the price of item #1: 1.09
Enter quantity of item #1: 5


Enter the price of item #2: 1.25
Enter quantity of item #2: 3


Enter the price of item #3: 3.69
Enter quantity of item #3: 7


Enter the price of item #4: 1.00
Enter quantity of item #4: 9

Your total purchase is $ 43.03
You are $ 18.03 over budget


Enter your budget $: 25.00

How many items are you buying? 4

Enter the price of item #1: 1.09
Enter quantity of item #1: 5


Enter the price of item #2: 1.25
Enter quantity of item #2: 3


Enter the price of item #3: 2.00
Enter quantity of item #3: 2

Enter the price of item #4: 1.00
Enter quantity of item #4: 8


Your total purchase is $ 21.02
You are $ 3.98 under budget.


Im totally lost here... thanks for ur help in advance! and remember I need the SIMPLEST form of programming, I have only been taking this course from 2 weeks so far...

thank you.

That seems a pretty advanced project for just two weeks into a course.

You'll find you won't get much in the way of specific help here till you show you've attempted to solve the problem yourself - show the work you've done, ask questions about problems you encounter.

Your samples don't agree with the problem statement - where is the input of sales tax or discount rates? Neither of those appear to factor into the output shown. Please be clear in your problem statement - we can't help you solve anything if we're solving something different.

Sit down with pencil and paper first - get your thoughts organized, take it one step at a time.

What input is needed, in what data type should you store it?
How will you control the main loop?
What processing do you do, what results/subresults must you store?

Actually I spent hours on it and nothing :/ I didn't quiet understand what you said last but i tried what you said, I tried to explain the problem logically, but nothing :/

I think I'm supposed to use a "DO WHILE" loop or a "For" loop, so says my instructor... but I can't get to work...
I tried to figure out the loop, but I don't know how to calculate the budget limit and all that,

I tried the following, but I couldn't figure out what to do in the end:

main(){

int budget,PriceItem1;
int QuantItem1;


cout << "Enter quantity of item #1: ";
cin >> QuantItem1;


for (int i = 1 ; i < 25 ; ++i){
cout << "Enter the price of item #1: " ;
cin >> PriceItem1;


etc....

two things right off.

Look at the type of data you're using. Can price values be stored as type int?

Don't start off with trying to store the quantity of item one, price of item one, quantity of item two, price of item two.....

Using a loop ( a for loop works for the sample run you gave, where the user tells you how many items there will be, otherwise a while or do...while will be needed. How does the user indicate end of input?) you just get a quantity and a price, calculate total for that item, add to the grand total. Get next quantity and price reusing the input variables.

Actually I spent hours on it and nothing :/ I didn't quiet understand what you said last but i tried what you said, I tried to explain the problem logically, but nothing :/

I think I'm supposed to use a "DO WHILE" loop or a "For" loop, so says my instructor... but I can't get to work...
I tried to figure out the loop, but I don't know how to calculate the budget limit and all that,

I tried the following, but I couldn't figure out what to do in the end:

main(){

int budget,PriceItem1;
int QuantItem1;


cout << "Enter quantity of item #1: ";
cin >> QuantItem1;


for (int i = 1 ; i < 25 ; ++i){
cout << "Enter the price of item #1: " ;
cin >> PriceItem1;


etc....

I agree with vmanes. Quite advanced for two weeks into the course if it's your first C++ course. You shouldn't hard-code in the 25 in your loop. In your example, you are to ask the user to enter the number of items, so you need to ask that and store it in a variable. The user's entry will have an effect on how you design your loop. Are you always going through your loop 25 times? If not, don't hard-code 25 in.

all true what you said, but I'm thinking more of the Command side, the C++ language is where I'm having trouble... I kinda know what to do in certain areas its just how to write the damn thing is vexing me :s

I agree with vmanes. Quite advanced for two weeks into the course if it's your first C++ course. You shouldn't hard-code in the 25 in your loop. In your example, you are to ask the user to enter the number of items, so you need to ask that and store it in a variable. The user's entry will have an effect on how you design your loop. Are you always going through your loop 25 times? If not, don't hard-code 25 in.

Ummm, well yea that's our professor he gives us some really tricky stuff...
As for my problem, well don't forget that at the end I have to make an evaluation of the result and display wether it is high/below budget...
As for the loop, the program have to ask the user 4 times about the 4 items and it seemed the only logical way to do it considering that the price of each item had to add up with the previous ( and then multiply it with the number of items bought )
C++ is very frustrating!! >.<

As for the loop, the program have to ask the user 4 times about the 4 items

It's four times because the user entered 4. It may not always be.

How many items are you buying? 4

You need to really sit down and draw out out a plan for this program. Figure out what you know how to do and what you don't. You need to prompt the user for some information, store that information in some variables, design a loop, figure out what to put inside the loop, what to put before, what to put after. What variables do you need. A good place to start? Set up a main function, ask the user to enter the number of items, design a loop around that response, and post that entire program, with all the #include statements and the full main function, so you have a fully functioning program, albeit one that doesn't do much at all. Just leave the loop empty for now. It'll be a start and it'll tell us whether you are able to do that part or not.

PFEW!! after several hard attempts the program works!!!!!!!!!!

float res, pres;
    int items;

    for (int i = 0; i < cant; i++ ) {           
        cout<<"Enter the price of item \#"<<i<<":"<<endl;
        cin>> pres;
        cout<<"Enter quantity of item \#"<<i<<":"<<endl;
        cin>> items;
        res += (pres * items);
    }

    budget = res - budget;

there was the trick!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.