Question
Double melonQuantity and string friendName are read from input. An ofstream named outFS is declared and the file named melon.txt is opened. Write the following
Double melonQuantity and string friendName are read from input. An ofstream named outFS is declared and the file named melon.txt is opened. Write the following to the opened file: "To buy:" followed by a newline melonQuantity followed by " kilograms of melons for ", friendName, and a newline Ex: If the input is 17.5 Maryam, then melon.txt contains: To buy: 17.5 kilograms of melons for Maryam
#include
int main() { ofstream outFS; double melonQuantity; string friendName;
cin >> melonQuantity; cin >> friendName; outFS.open("melon.txt"); if (!outFS.is_open()) { cout << "melon.txt" << " could not be opened." << endl; return 1; } /* Your code goes here */ outFS.close(); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started