## boyjim32 -1

Problem 2:

Write a program which will accept the price and description of three items.

It will then display the total price of the three items as its output.

Here is a sample output:

First Item: ruler

Enter price: P 32.50

Second item: notebook

Enter price: P 25.00

Third item: ballpen

Enter price: P 12.75

ITEM PRICE

----------------------------------

lasagna P 32.50

iced tea P 25.00

macaroons P 12.75

----------------------------------

TOTAL: P 70.25

commented: Homework should be done by you, show your effort if you want help ! -1

## csurfer 422

Well we will help you for sure.Here are a set of good books from which you can learn.<USEFUL BOOKS>.
Read all this write a program and then if you have problems come back with your code we will do more than just helping you.Till then enjoy your studies.You wont get any help here.

This is a community for learners and no help is given to lazy people.

I wont say that you are chickening out of writing codes or getting lazy but until you try you wont be able to code.So start your coding now and we will help you with all our might.

We too started the same way and soon you will be one among us so start coding and start studying.

thnx

## boyjim32 -1

they don't have i need to finished it this day because I'm going to submit it...

## boyjim32 -1

do i need to code it first???

## boyjim32 -1

i really don't know how to start T____T

## iamthwee 1,547

You can probably hard code the lot without any loops.

Just declare three string variables and three double variables.

Add all the numbers together and show at the end maybe?

## Hiroshe 499

do i need to code it first???

Well, for a simple problem like this, you might. But for bigger problems, planning out the program is a must. Uhh... Why would someone who dosent know how to program in the first place be asked this? What ever the reason, here is a good place to learn C++. Good luck.

## ALI INAM -8

``````#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
double a = 0;
double b = 0;
double c = 0;
char t = '\t';
int i = 0;
double total = 0;
using namespace  std;
do {
++i;
int main () {
string line1, line2 , line3;
std::cout << "First Item: " << std::endl;
getline(cin, line1);
std::cout << "Second Item: " << std::endl;
getline(cin, line2);
std::cout << "Third Item: " << std::endl;
getline(cin, line3);
std::cout << ' ' << std::endl;
std::cout << "Enter Price for first item " << std::endl;
std::cin >> a;
std::cout << "Enter Price for second item " << std::endl;
std::cin >> b;
std::cout << "Enter price for third item " << std::endl;
std::cin >> c;

std::cout << ' ' << std::endl;
std::cout << ' ' << std::endl;
std::cout << "ITEM PRICE " << std::endl;
std::cout << ' ' << std::endl;
std::cout << "--------------------------------------------------" << std::endl;
std::cout << line1 << t << a << std::endl;
std::cout << ' ' << std::endl;
std::cout << line2 << t << b << std::endl;
std::cout << ' ' << std::endl;
std::cout << line3 << t << c << std::endl;
std::cout << ' ' << std::endl;
std::cout << ' ' << std::endl;
std::cout << ' ' << std::endl;
total = a + b + c;
std::cout << "------------------------------------------------" <<std::endl;
std::cout << "TOTAL" << t << total << std::endl;
cin.get();

}while (i < 5);
}``````

i hope this helps you more then it helps me and all of you are mo9st welcome to improve it and best of all critise on ot

commented: Trying to solve someone else his homework is not what should be done ! -1
commented: Remember: don't give free code! -3
commented: No free cookies here. -4

## JoBe 36

The idea is to help him create HIS own code, not to give a possible solution ! You're not helping him with this, on the contrary !

commented: Quite so. +36

## 23.12.2012 22

``````#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
...
}while (i < 5);
}``````

i hope this helps you more then it helps me and all of you are mo9st welcome to improve it and best of all critise on ot

Have you tried compiling the code before posting? You're using both `using namespace std;` and `std::` , which makes no sense for me. Also, I can't seem to find the part where you write lines to a file, so there's no point in using fstream. And why did you use `i < 5` ? If i is initialized to 0, then it should go through the loop 4 times.
Is the code wrong, or am I missing something?

@boyjim32 what you have to do is extremly easy. It should be covered entirely in the first chapter of most C++ books. It's basically input/output and language-specific features. I'd dare to say C++ Without Fear would be a good place for you to start.

## ALI INAM -8

well i compiled it before and after you told me and it worked perfectly
i know that there are some glitches in it but minor ones that does not
invoke compilation errors and you are not missing any thing i am a mear 16 year old boy who started programming 2 weeks earlier

## 23.12.2012 22

I don't know what compiler you are using, but I suggest you switch to the GNU C++ Compiler right away (google it). If you're using UNIX/Linux, download it. If you're using OS X, you've already got it. If you're running Windows, have a look over MinGW.

If you recompile your code with this, you'll find many many errors.

By the way, DO is outside MAIN, which is another UGLY mistake.

``````Documents/test.cpp:1: error: stray ‘\’ in program
Documents/test.cpp:1: error: stray ‘\’ in program
Documents/test.cpp:1: error: stray ‘\’ in program
Documents/test.cpp:1: error: stray ‘\’ in program
Documents/test.cpp:1: error: stray ‘\’ in program
Documents/test.cpp:2: error: stray ‘\’ in program
Documents/test.cpp:2: error: stray ‘\’ in program
Documents/test.cpp:2: error: stray ‘\’ in program
Documents/test.cpp:2: error: stray ‘\’ in program
Documents/test.cpp:3: error: stray ‘\’ in program
Documents/test.cpp:3: error: stray ‘\’ in program
Documents/test.cpp:3: error: stray ‘\’ in program
Documents/test.cpp:3: error: stray ‘\’ in program
Documents/test.cpp:4: error: stray ‘\’ in program
Documents/test.cpp:4: error: stray ‘\’ in program
Documents/test.cpp:4: error: stray ‘\’ in program
Documents/test.cpp:4: error: stray ‘\’ in program
Documents/test.cpp:4: error: stray ‘\’ in program
Documents/test.cpp:4: error: stray ‘\’ in program
Documents/test.cpp:4: error: stray ‘\’ in program
Documents/test.cpp:5: error: stray ‘\’ in program
Documents/test.cpp:6: error: stray ‘\’ in program
Documents/test.cpp:6: error: stray ‘\’ in program
Documents/test.cpp:6: error: stray ‘\’ in program
Documents/test.cpp:6: error: stray ‘\’ in program
Documents/test.cpp:8: error: stray ‘\’ in program
Documents/test.cpp:8: error: stray ‘\’ in program
Documents/test.cpp:8: error: stray ‘\’ in program
Documents/test.cpp:8: error: stray ‘#’ in program
Documents/test.cpp:8:34: warning: backslash-newline at end of file
Documents/test.cpp:8: error: stray ‘#’ in program
Documents/test.cpp:8: error: stray ‘#’ in program
Documents/test.cpp:8: error: stray ‘#’ in program
Documents/test.cpp:15:10: warning: multi-character character constant
Documents/test.cpp:8: error: stray ‘\’ in program
Documents/test.cpp:8: error: stray ‘\’ in program
Documents/test.cpp:8: error: stray ‘\’ in program
Documents/test.cpp:8: error: stray ‘\’ in program
Documents/test.cpp:1: error: expected unqualified-id before ‘{’ token``````

## mvmalderen 2,072

>well i compiled it before and after you told me and it worked perfectly
Sorry buddy your rubbish doesn't compile, what compiler are you using?
BTW, why so much global variables, ever heard of local variables?

Your code compiles with me, after removing `#include "stdafx.h"` and moving this block inside main:

``````do {
++i;``````

@23.12.2012:
Could it be that you didn't click: Toggle Plain Text before you copied his code?
I suggest you to not spend any word extra on him.

## 23.12.2012 22

Can't see any changes. It still doesn't compile and I get the same errors. The GNU C++ Compiler.

Anyway, the code is a complete mess. It's clear that he hasn't understood anything. If you've specified that you're `using namespace std` , why bother writing it 4957340987 times?

The variables are global, although there's a single function, and overall, you can't understand much from that code. Especially with all those "-----" lines.

## mvmalderen 2,072

Can't see any changes. It still doesn't compile and I get the same errors. The GNU C++ Compiler.

Probably because you're on a Mac then, Windows and Mac handle a newline in a different way.