Display the price of the inputed item and display the total price of the inputed quantity of the item

Feb 23, 2013 at 3:32am
I need to make a program in cplusplus.. Here's the instruction:

make a program that when the user input an Item name it will display or print the price of the inputed item, and when the user inputed the quantity of the item he inputed, it will display the total price.

Here's the output:

Item name:
Price:
Quantity:
Total Price:

here is the list of item of choice that will be inputed by the user:

(Item)- (Price)
cellphone - 1500
washing machine - 5200
television - 6000
refrigirator - 8000
oven - 2000
computer - 11000

here's my wrong codes but runs in my compiler :D..

By the way here it is:

#include <iostream.h>
#include <conio.h>
int main()
{
clrscr();
char a[20];
int oven=2000;
int washing machine=5200;
int television=6000;
int refrigirator=8000;
int cellphone=1500;
int computer=11000;
cout<<"Enter Product name: ";
cin>>a;
if (oven)
cout<<"Price: 2000";
if(cellphone)
cout<<"Price: 1500";
if(washing machine)
cout<<"Price: 5200";
if(television)
cout<<"Price: 6000";
if(refrigirator)
cout<<"Price: 8000";
if(computer)
cout<<"Price: 11000";
getch();
}

(im just trying first to display the price of the inputed item that's why i did not set a syntax for quantity input)

and here's the output of my work:
Product Name: oven
Price: 2000
Price: 1500
Price: 5200
Price: 6000
Price: 8000
Price: 11000

even what item i input.. It displays all the items price..XD what should i do about this?
Feb 23, 2013 at 4:43am
first you cant have spaces in variable names so the fallowing is wrong
 
int washing machine=5200;

next
 
if (oven)

and all of your if statements for that matter will always evaluate to true since those variables all have non 0 values.
what you want to do in the if statement is check if a is the word "oven" or whatever.
Feb 23, 2013 at 5:35am
So what i must do to make it run correctly.. Like if i inputed the item "cellphone"
it will display the price of that item not all the price of all the items? XD
i think if i make it correctly, i can apply it to the "quantity and total cost" part.
Topic archived. No new replies allowed.