Hi all, I am very new so excuse the messy code. I am just trying to get this code to work properly first before cleaning it :p . For now I want it to: if user types "no" exit, if user types "yes" then run the next part, or if the user inputs anything else, it repeats the previous step (asking yes or no). At the moment, if the user types anything but "yes" it still tries to give it a price for some reason. I also want it to say the quantity of the apples, but unsure how to make a function return more than 1 thing.
#include <iostream>
#include <string>
using namespace std;
int quant(int qnty, int price)
{
int sum;
sum = qnty * price;
return (sum);
}
int apples(int a)
{
string yn;
int answer, qnt;
int appleprice = 1.2;
cout << "\nWould you like some apples?";
cin >> yn;
if (yn == "yes" || "y" || "yeah" || "yep")
answer = 1;
if (yn == "no")
answer = 2;
switch(answer)
{
case 1:
{
cout << "\nHow many apples would you like? They are $1.20 ea.";
cin >> qnt;
quant(qnt,appleprice);
}
break;
case 2:
{cout << "\nOkay";
}
break;
default:
{cout<<"\nlolwut?";
return 0;
}
}
cout << "\nThe price for " << qnt << " is: " << appleprice;
return (a);
}
int main()
{
int a;
cout << "\nWelcome to the fruit shop!";
cout << "\nWe only have apples at the moment.";
apples(a);
cout << a; //It keeps telling me "a" is uninitialized, which I dont care, is
//there a better way to word this?
main();
return 0;
}