Hi,
I have created a program that takes a users input, runs it through a if, else if, else, and prints a result on the screen. I have also set it up so that it creates a text file (which I am hoping to display what I have it printed out on the screen). Heres what I have:
Code:
#include <iostream>
#include <fstream>
using namspace std;
int main()
{
int number;
char numberwithspelling[50]
cout<<"Type A Number Between 1 and 20: ";
cin>>number;
cin.ignore();
if(number==0)
{
cout<<"Please enter a valid number";
}
.....
if(number==20)
{
cout<<"You Entered The Number Twenty";
}
else
{
cout<<"Please enter a valid number";
}
cin.get();
std::ofstream outfile ("test.txt");
std::ostream &out = outfile;
out<<numberwithspelling<<endl;
Return 0;
This is fine, and I do want to create a text file, but at the same time, I would like to have that text file filled with the variable, which I can change for the different if statements. Heres what I want to do:
Code:
#include <iostream>
#include <fstream>
using namspace std;
int main()
{
int number;
char numberwithspelling[50]
cout<<"Type A Number Between 1 and 20: ";
cin>>number;
cin.ignore();
if(number==0)
{
cout<<"Please enter a valid number";
}
.....
if(number==20)
{
cout<<"You Entered The Number Twenty";
numberwithspelling<<"You Entered The Number Twenty";
}
else
{
cout<<"Please enter a valid number";
}
cin.get();
std::ofstream outfile ("test.txt");
std::ostream &out = outfile;
out<<numberwithspelling<<endl;
Return 0;
Is there any way I can assign the value for numberwithspelling in the if statement?
Thanks for all your help!
FlyingIsFun1217