/* QUESTION */
/* Write a function named getPrice
It takes in one parameter called size which is a character and
returns the price depending on the size
When size is 'L' return 20.00
When size is 'M' return 15.00
When size is 'S' return 10.00
For all other chars, return -1
Use switch case statement
*/
#include <iostream>
usingnamespace std;
double getPrice(char size){
cout << "Enter size: ";
cin >> size;
double price = 1;
switch(size){
case'L':
price = 20.00;
break;
case'M':
price = 15.00;
break;
case'S':
price = 10.00;
break;
default:
price = -1;
}
return price;
}
int main(){
cout << getPrice();
}
The error says No matching function for call to 'getPrice'. I don't understand why it isn't running
On line 15, double getPrice(char size), it takes a parameter of char data type; however, when the main function calls it at line 38, cout << getPrice(); you will get an error because those functions are not the same.
/* QUESTION */
/* Write a function named getPrice
It takes in one parameter called size which is a character and
returns the price depending on the size
When size is 'L' return 20.00
When size is 'M' return 15.00
When size is 'S' return 10.00
For all other chars, return -1
Use switch case statement
*/
#include <iostream>
#include <iomanip> // For the use of std::fixed and setprecision(2)
usingnamespace std;
double getPrice() {
char size{};
cout << "Enter size: ";
cin >> size;
double price = 1;
switch (size) {
case'L':
price = 20.00;
break;
case'M':
price = 15.00;
break;
case'S':
price = 10.00;
break;
default:
price = -1;
}
return price;
}
int main() {
cout << fixed << setprecision(2);
cout << getPrice();
}
/* QUESTION */
/* Write a function named getPrice
It takes in one parameter called size which is a character and
returns the price depending on the size
When size is 'L' return 20.00
When size is 'M' return 15.00
When size is 'S' return 10.00
For all other chars, return -1
Use switch case statement
*/
#include <iostream>
usingnamespace std;
double getPrice(char size){
cout << "Enter size: ";
cin >> size;
double price = 1;
switch(size){
case'L':
price = 20.00;
break;
case'M':
price = 15.00;
break;
case'S':
price = 10.00;
break;
default:
price = -1;
}
return price;
}
int main(){
char size;
cout << "Enter size: ";
cin >> size;
cout << getPrice(size);
}
However, the cout statement is running twice. Is there a reason why?
The reason is calling it twice is because it calls for the size in the main function and then once the getPrice(size) is called, then it ask the size from the getPrice(size) at line 16 and line 17.