I keep getting an error with my solution because I cant use strtof in visual studio due to not being supported. I get an error saying is undefined on line 28. Is there anything i can use to run this program properly.
Ch9_Ex4Data.txt. The input text file is
Plain Egg
1.45
Bacon and Egg
2.45
Muffin
0.99
French Toast
1.99
Fruit Basket
2.49
Cereal
0.69
Coffee
0.50
Tea
0.75.
#include<iostream>
#include<cstdlib>
#include<string>
#include<fstream>
#include<stdlib.h>
using namespace std;
struct menuItem
{
string item;
float price;
int quantity;
};
menuItem* breakfastMenu = new menuItem[8];
void getData()
{
ifstream myfile ("Ch9_Ex4Data.txt");
if (myfile.is_open())
{
string line;
int i=0,flag=1;
while ( getline (myfile,line) )
{
if(flag){
breakfastMenu[i].item = line;
flag=0;
}
else{
breakfastMenu[i++].price = (float)strtof(line.c_str(),NULL);
flag=1;
}
}
}
else cout << "Unable to open file";
myfile.close();
}
void printCheck()
{
float billAmount;
for(int i=0;i<8;i++)
{
if(breakfastMenu[i].quantity > 0)
{
cout< billAmount += breakfastMenu[i].quantity * breakfastMenu[i].price;
}
}
cout<<"Amount Due $"< }
void showMenu()
{
int num,quantity;
char c;
for(int i=0;i<8;i++)
cout<<(i+1) <<". " < cout<<"What would you like to have?"< cin>>num;
cout<<"Quantity?"< cin>>quantity;
breakfastMenu[num-1].quantity = quantity;
cout<<"Print check?(y/n)"< cin>> c;
if(c=='Y' || c=='y')
printCheck();
else
showMenu();
}
int main()
{
getData();
showMenu();
system("pause");
return 0;
}