Using selection criteria method, construct a program to output the following total cost in each case.
i. If vitamins sold <=20 and cost is 0.05 pence per vitamin.
ii. If vitamins sold between 21 and 49 inclusive then cost is 0.04 pence per vitamin.
iii. If vitamins sold >49 then cost is 0.03 pence per vitamin
// Filename: PROJECT7. CPP
// Uses a switch statement to control a user's selection.
#include "stdafx.h"
#include <iostream>
#include<iomanip>
#include <stdio.h>
usingnamespace std;
void main()
{
int menu;
float charge = 0.00; // Holds total charge
cout << "** Computer Repair Center **\n\n";
cout << "What work was performed? Here are the choices: \n\n";
cout <<"\t1. Replaced the CPU and RAM\n";
cout <<"\t2. Replaced the RAM only\n";
cout <<"\t3. Repaired the monitor\n";
cout <<"\t4. Fixed stuck keys\n";
do
{
cout << "\nwhat work was performed?";
cin >> menu;
}while ((menu < 1) || (menu > 4));
// Store charge based on the repair person's input
switch (menu)
{
case (1): {charge = 200.00; } // Notice no break here
case (2): {charge += 150.00; break;}
case (3): {charge = 75.00; break;}
case (4): {charge = 12.00; break;}
}
// Print.the results
cout << setprecision(2);
cout.setf(ios::showpoint);
cout.setf(ios::fixed);
cout << "\nthe total charge is $" << charge << "\n\n";
system("pause");
return;
}
I have no idea where to input the numbers given on the question and how to multiply them so if anyone kind enough to help me please would really helpful
Remove the first #include (select empty project in the setup)
void main()?
What's the parentheses in the switch cases for, case (1) etc. And why do you end the break statements with '}'
thanks for you reply Nathan if you look the code below im trying to work out case are questions to buyers if say if someone buys vitamins 1-29 price will be 0.05
if 21 to 49 price will be 0.004
and 49 or more 0.03
if it make any sense :(
If vitamins sold <=20 and cost is 0.05 pence per vitamin.
If vitamins sold between 21 and 49 inclusive then cost is 0.04 pence per vitamin.
If vitamins sold >49 then cost is 0.03 pence per vitamin
// Filename: PROJECT7. CPP
// Uses a switch statement to control a user's selection.
void main()
{
int menu;
float charge = 0.00; // Holds total charge
cout << "** vitamin shop **\n\n";
cout << "What work was performed? Here are the choices: \n\n";
cout <<"\t1. If vitamins sold <=20 and cost is 0.05 pence per vitamin\n";
cout <<"\t2. If vitamins sold between 21 and 49 inclusive then cost is 0.04 pence per vitamin\n";
cout <<"\t3. If vitamins sold >49 then cost is 0.03 pence per vitamin\n";
do
{
cout << "\nwhat work was performed?";
cin >> menu;
}while ((menu < 1) || (menu > 3));
// Store charge based on the repair person's input
switch (menu)
{
case (1): {charge *= 0.05; } // Notice no break here
case (2): {charge *= 0.04; break;}
case (3): {charge *= 0.03; break;}
}
I have no idea why my tutor used break I just changed the word and numbers.
say if i want to buy 20 vitamins i want the 20 to * with 0.05 and get me the result's if you know what im trying to say
You are going to want to use if/else statements here instead of a switch. You can look here for more info on both statements if you are confused: http://www.cplusplus.com/doc/tutorial/control/
I would start the program off by asking the user how many vitamins they would like to buy. Then you can use if/else to find out which price they get (i.e