the problem lies in the strcmp line, you have "memory card", you have to fix the space. I revised the code and pasted the program as i got it to work, notice the _ to fill the space. I forget how to re-write that strcmp line correctly, but a lil researching on the boards and u'll be fine.
Also not everything has to be a double, hence your bad spitting numbers problem. num_of can be a int, as no one is going to order 1.5 sticks of memory. Same as times, no one is going to run this loop 1.5 times (not in a day to day situation anyway).
output:
Code:
How many items would you like to buy? 2
Which item would you like to buy? memory_card
How many?: 4
number of = 4
Which item would you like to buy? memory_card
How many?: 4
number of = 4
Your total is 559.60
Press any key to continue
revised code:
Code:
#include <iostream.h>
#include <string.h>
#include <iomanip.h>
const double mem_card = 69.95;
const double software = 34.98;
const double nw_pc = 675.00;
const double disk_drive = 198.50;
#define FLAGS cout<<setiosflags(ios::fixed | ios::showpoint | ios::right)<<setprecision(2);
int main()
{
double total = 0;
char item[30];
int num_of;
int times;
/* int memory;
int soft;
int nw;
int disk;*/
FLAGS;
cout << "How many items would you like to buy? ";
cin >> times;
for(int i = 1;i <= times;i++)
{
cout << "Which item would you like to buy? ";
cin>>item;
cout<< "How many?: ";
cin>>num_of;
cout<<"\n";
cout << "number of = " << num_of << endl;
if(strcmp(item,"memory card"))
total = total + (mem_card * num_of);
else if(strcmp(item,"software"))
total = total + (software * num_of);
else if(strcmp(item,"new pc"))
total = total + (nw_pc * num_of);
else if(strcmp(item,"disk drive"))
total = total + (disk_drive * num_of);
else
cout << "That is an invalid choice.\n";
}
cout << "Your total is ";
cout << setprecision(2) << total << endl;
return 0;
}