0

Hello,

So I have a .txt file which is kind of built like:

N 1234554321 Joe Jones
Y 1234555432 Sarah Clark
Y 1234321231 Kirah Williams
N 1234212321 John Johnston

The output, line by line, as the txt file is, and it works and all,
I output "Y" or "N"
I store "numbers" in an ans[] array
and I call the name using

string name;
getline (inFile, name);
cout << name;

However, I do not know how to make an error statement for if

Y 1233420321 Sally James

to print like
Y 1233423321 Sally James
*** one variable changed to 3 ***

...so the error message prints after calling void functions to read in the rest of the numbers, print them, and the void to call the name. The ERROR should be printed the line after.

int main
{
bool replacenum = false; //a bool flag

...

while (infile >> letter)
{
   ...
   for (int=0 ; i < SIZE ; i++)
   {
   inFile >> ans1[i];
   
   if ((ans1[i] < 1) || (ans1[i] > 5))
   {
   ans1[i]=3;
   replacenum=true
   }
   }
    
   if (replacenum=true)
   {
   cout << "*** one variable changed to 3 ***" << endl;
   }
}

return 0;
}
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by VernonDozier
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.