hi, i am trying to make a weight watchers program and heres my code:
#include<iostream>
#include<fstream>
#include<conio.h>
#include<cstdio>
#include<windows.h>
using namespace std;
int main (char argc)
{
for(;;)
{
system("cls");
ifstream r;
r.open("cdaily.txt");
double r1;
r >> r1;
r.close();
ifstream r2;
r2.open("cweekly.txt");
double r3;
r2 >> r3;
r2.close();
cout << "You have "<<r1<<" daily points left for the day." << endl;
cout << "You have "<<r3<<" weekly points left for the week." << endl;
cout << "1: Eat new food (from daily) \n2: Eat new food (from weekly) \n3: Reset daily points (new day) \n4: Reset weekly points (new week) \n5: Change daily points \n6: Change weekly points \n7: Week review \n8: Exit" << endl;
int z = getch();
if(z == 56)
{
return 0;
}
if(z == 53)
{
system("cls");
ofstream daily;
daily.open("daily.txt");
float d;
cout << "Enter new daily points." << endl;
cin >> d;
daily << d;
daily.close();
ofstream daily1;
daily1.open("cdaily.txt");
daily1 << d;
daily1.close();
cout << "Done." << endl;
Sleep(2000);
}
if(z == 54)
{
system("cls");
ofstream weekly;
weekly.open("weekly.txt");
float w;
cout << "Enter new weekly points." << endl;
cin >> w;
weekly << w;
weekly.close();
ofstream weekly1;
weekly1.open("cweekly.txt");
weekly1 << w;
weekly1.close();
cout << "Done." << endl;
Sleep(2000);
}
if(z == 51)
{
ofstream daily2;
daily2.open("cdaily.txt");
ifstream daily3;
daily3.open("daily.txt");
double n2;
daily3 >> n2;
daily3.close();
daily2 << n2;
daily2.close();
cout << "Done." << endl;
Sleep(1500);
}
if(z == 52)
{
ofstream weekly2;
weekly2.open("cweekly.txt");
ifstream weekly3;
weekly3.open("weekly.txt");
double n3;
weekly3 >> n3;
weekly3.close();
weekly2 << n3;
weekly2.close();
cout << "Done." << endl;
Sleep(1500);
}
if(z == 49)
{
int l = 0;
ofstream rday;
rday.open("rday.txt");
ofstream loop;
loop.open("loop.txt");
string f;
double p;
cout << "Enter the food you ate." << endl;
getline(cin,f);
cout << "Enter the amount of points "<<f<<" is." << endl;
cin >> p;
rday.seekp(0, ios::end);
rday << "Daily food. "<< f << ". Points = "<<p;
l++;
loop << l;
rday.close();
cout << "Done." << endl;
Sleep(1500);
}
}
}
I havnt finished it yet but here are my problems, when i eat a new food and record it, i want the program to put everything i have eaten in a text file all in a list. Also, when i record a food i ate and go to the main menu and record another food, the program doesnt let me input the food name. Any solutions?