how to separately add two statements into a file text?
Sep 8, 2013 at 12:53pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
void cakeType ()
{
int id;
cout << "Cake ID Flavor" << endl;
cout << "0101: Chocolate" << endl;
cout << "0102: White chocolate" << endl;
cout << "0103: Vallina" << endl;
cout << "0104: Peanut butter" << endl;
cout << "0105: Coconut" << endl;
cout << "0106: Italian creme" << endl;
cout << "0107: Raspberry" << endl;
cout << "0108: Banana" << endl;
cout << "0109: Lemon" << endl;
cout << "0110: Apple" << endl;
cout << "Enter the cake id :" ;
cin >> id;
}
switch (option)
{
case '1' :
{
cin.ignore();
cout << "Enter your name:" ;
getline(cin,name);
cout << "Enter the diameter:" ;
cin >> diameter;
cout << "Enter the height:" ;
cin >> height;
radius = diameter / 2;
volume = radius * height * pi * 2;
price = volume * inch;
cout << "Price is:" << price << endl;
ofstream myfile;
myfile.open("test1.txt" , ofstream::out | ofstream::app);
myfile << i++ << " " ;
myfile << name << " " ;
myfile << volume << " " ;
myfile << price << endl;
myfile.close ();
}
break ;
case '2' :
{
cakeType ();
}
Sep 8, 2013 at 12:54pm UTC
after finish the case 1 details... then the id that i enter will be the second line... how can i make it same line?
Sep 8, 2013 at 1:33pm UTC
You question is not clear to me.
At line 16, you input the id. The id will be followed by entering a carriage return.
Is that what you're trying to eliminate?
how can i make it same line?
I assume you mean id, but on the same line as what?
Sep 8, 2013 at 1:41pm UTC
for example:
1. kevin volume price id
i want to make text like the previous i have written
but unfortunately, the output is
1. kevin volume price
id
Sep 8, 2013 at 2:24pm UTC
You do write explicit std::endl after price in your code. You do close the output file there too. Neither makes it easy for you to achieve what you want.
Topic archived. No new replies allowed.