User Profile
Collapse
-
How do you write to a file one line at a time?
I am in the planning stages of a project I am going to be building and for one part I am going to need it to write a string to a file one line at a time. The overall goal is for it to write one line each time the program is run.(Similar to storing "High Scores" in a game.) I am still learning C++ and my text book only explains writing data to a file as a whole not adding data on to existing data in a file. I am using <fstream> and... -
Lol no I went back and changed that, but the method you suggested
if(....)
correct = 'c'
.
.
.
if(answer == correct || answer == correct - 32)
worked perfectly!
I have never tried to do it that way and didn;t even think about the numeric difference between upper and lower case. To all that have given me assistance thank you so much, not only have I work this problem... -
I tried this and the extra '=' doesn't give the errors as before, but it still treats all input as the correct answer. So is there an issue with assigning the value to 'correct' or in the loops in line 79 and 85 or both? Thanks for all the help.Leave a comment:
-
Thank you for the quick reply. If I change the ' if ' statement expressions to
(i = 5 || i = 7 || i = 9 etc...) it gives numerous error codes with this. The error code I get is "error C2106: '=' : left operand must be l-value" I am using Visual studio 2008 if that matters. What I want it to do is to assign the right value to the variable 'correct' based on the random value of ' i '. Thats why I wrote this the way I have. That way...Leave a comment:
-
Loop problem
I am making a trivia game and I am having some issues with a loop in it. When it runs it show all answers are right. The game is based on a 3 strike system, you get three strikes and the games over and it awards 1 point for each right answer. What am I missing? I am new to programming and haven't run into a problem like this to troubleshoot. I am using a parallel array to read in all the questions and chioces. An everything is working except getting... -
Our text book doesn't cover string arrays in much detail, and up until now I've only had to work with int arrays. As someone wanting to learn to learn this I am thankful that you didn't just give me a line of code that works. By just pointing me in the right direction and letting me solve this for myself I feel is the best way to learn from my mistakes. Than you once again!Leave a comment:
-
Thank you for a quick response. The only reason I am using a do...while loop is because that is what my instructor is looking for. "Using a do…while() loop, print out the 1st and 3rd letters of each word (two letters per line) using the substring function." What I have does that for the last element "END_OF_ARR AY", so is the problem printing this out in the do...while loop or in the way the data is stored into the array from...Leave a comment:
-
Dbarten1982 started a topic How do I get user input into a string array then display the data entered?in CHow do I get user input into a string array then display the data entered?
I am brand new to C++ programming, and am completely stuck on a program.
In the program I am supposed to create a string array that stores 5 user input words, and the string constant "END_OF_ARR AY' in the last element. Then using the substr() display the first and third letter of each element. What I have now gets five word from the user, then it just displays the 1st and 3rd letter of the constant "END_OF_FIL E" I don't know...
No activity results to display
Show More
Leave a comment: