Allowing a test to run again C++ - c++

I'm new to Stack Overflow and would just like to thank all the people that have unknowingly helped me so far. Anyhow, I'm currently writing the pseudocode for a program in which multiplication problems are generated for the user to answer. My professor wants this program to run until the user enters a sentinel value that would stop asking the user questions, and then display a report of how many questions they correctly answered and so forth.
All of that makes sense to me, and I'd probably be able to code most of that right now without struggling much. However, at the end of the direction sheet, it says "Your program should then repeat the process for another test taker". I'm not entirely sure how I'd go about doing that, since I have a 'while loop' running until the user terminates the program. The pseudocode is as follows:
BEGIN Lab 4 - Multiplication Program
Mult_Num_1 = Random positive single digit number
Mult_Num_2 = Random positive single digit number
Calculate the product
Display the multiplication problem, and sentinel value to quit
User inputs an answer
WHILE ( Answer != QUIT )
IF ( Answer == Product )
Inform user they are correct
Add 1 to Correct_Counter
Add 1 to Question_Counter
ELSE
Inform the user they are incorrect
Display the correct answer
Add 1 to Question_Counter
END IF
Calculate percentage of correct questions
Clear screen
Mult_Num_1 = Random positive single digit number
Mult_Num_2 = Random positive single digit number
Calculate the product
Display the multiplication problem, and sentinel value to quit
User inputs an answer
END WHILE
Display test report
END Lab 4 - Multiplication Program
I'd assume something needs to go after displaying the test report? I'm not entirely sure, but any help would greatly be appreciated. Thank you for taking your time to look over this!

Related

How can I create a loop that terminates at any desired year (C++)?

I was faced with creating a program that can tell a user how much interest will be added to a product after any arbitrary number of years. I had to use a loop to estimate the new price, among other things.
The problem I ran into was in the creation of the loop. I didn't know how to make it stop at any specific year that a user chose. What I did is made a for loop that outputted the loop for the next 99 years. This was my loop:
for (time>0; time<=99; time++) where time was the number of years from today.
This is obviously not ideal. I wrote this in frustration from not knowing how to create a loop that can end wherever the user wants. How can I create a loop that terminates at any desired year?
for (time>0; time<=99; time++)
This will stop at a predefined number, i.e. 99. To make it stop at a number given by user you need to:
Get the number from the user and save it in a variable
Replace 99 with the variable in your loop

How to create and calculate a formula using an unknown number of variables in C++

Okay, so this is going to be very complicated to explain through text but I will do my best to try.
I am making a universal calculator where one of the function of the calculator is to process a formula when given an unknown number of variables. I have seen some ways to do this but for how i'm trying to use this calculator, it wont work.
Example for sum of function:
while (cin >> input)
count++;
Normally this would work but the problem is that I can't have the user input the values over and over again for one formula like for this formula: Formula Example
(Sorry its easier for me to explain through a picture) In it there are multiple times where I have to use the same numbers over and over again. Here is the entire process if you need it to understand what I'm saying:
Entire problem
The problem is that normally I would add another float for every point graph but I don't know ahead of time number of floats the user is going to enter in. The ideal way to do this is for the program to ask the user for all the points on the table and for the user to input those points in a format like: "(1,2) (2,4) (3,6)..."
Thinking ahead, would I make a function where the program creates an integer and assigns the integer to a value on the fly? But then how would the actual math formula interact with the new integers if they haven't been created yet?
Talking about this makes my head hurt....
I actually want to say more:
One idea that I tried to make in my head was something like
string VariableName = A [or something]
Then you would reassign VariableName = "A" to VariableName = "B" by something like VariableName = "A"+ 1 (which would equal B).
Then you would repeat that step until the user inputs a invalid input. But obviously you can't do math with letters so I wouldn't know how to do it.
I think that you are overthinking this. It's pretty simple and it doesn't need to store the input values.
The main thing to note is that you need to compute (step 2) the sum of the values of X and Y, the sum of their product and the sum of X squared. To compute the sum of a lot of values you don't need all the values together, but just one at the time. Exactly as when a user provides them. So declare four variables: sx, sy, sxy, sxx. Initialize them to 0. At every couple of X and Y you get, add it to sx and sy, add their product to sxy and the product of X with itself to sxx.
Now you've got all you need to compute the final result for a and b.
Anyway a good C++ book would be useful.

Python - Need to cut user input and run the numbers in a loop

I'm not that great at python just getting snippets from here and there.
Right now I have user input, button click that runs the user's input and that is working for individual single inputs.
I am trying to make a user input with multiple answers
Example "1, 2, 5, 7, 23" -> To infinity amount
When submitted I need those answers to run in a loop until they are all used up.
So 5 answers would run the loop 5 times, each time using a different number from the user input.
By "each time using a different number" I mean I will be running a modbus coil command and those integers will be the coil address. Thus turning on or off those coils via the running loop.
So something like..
usernumbers = self.txtinput.get_text()
usernumbers.split()
usernumbersamount = len(usernumbers.split()
while usernumbers <= useramount:
modbus command goes here
Thats about as far as I can get of it will even work, Maybe it needs to be in an array for it to work?
sorry if user input looks funny this will be ran in a browser
Thanks!!
If the user separates the numbers using always the same character (space for instance) you can write:
usernumbers = self.txtinput.get_text()
for coil_address in [usernumbers.split()]:
self.run_coil_command(coil_address)
Change the split() by providing the separator used in you application: split(','), split(':'), ...

Unable to see whole output list on screen in C++ (Not even using scroll)

Ok, I just added a new feature to my student manager program (a console program written in c++) , it is a console application and my program print dates on which particular student is absent in a list format
by saying list format i mean 1 date on 1 line
this is how output looks like for student who is absent 5 times
1. 04/05/2016,Monday
2. 05/05/2016/Tuesday
3. 06/05/2016/Wednesday
(Assume dates are correct)
now since these are only 3 records that are printed on the screen, a user would not require scrolling down,
but in a case of 300 dates , it prints all dates but when i scroll up I'm not able to reach back to 1st date, for example, I'm only able to see last 147 Records only
and I'm not able to scroll my console window to 1st record.
I know many other ways to solve this problem (like displaying 10 records or 100 records at a time) but I want to know how can i solve this particular problem
please give answer considering me as a beginner. :)
Thank You.
(as far as code is concerned, i can assure you its nothing special, just a while loop that keeps on printing dates until certain terminating condition is met )

Psychopy: Key response lagging, causing problems within script

I have a component of an experiment that asks participants to choose between earning 10 immediate points or a larger point amount in two weeks (points are later converted to dollar amount to provide incentive to the "larger later" choice). The later amount offered varies based on previous choices. The participant is given feedback on the choice he/she just made in the next routine. To set this up, I generated this in the code component in builder:
if key_resp_4.keys == 'left':
feedback = 'You chose 10 points immediately'
TotalNow = TotalNow + 10
add = (amount - 10)/2
amount = add + amount
elif key_resp_4.keys == 'right':
feedback = 'You chose more points in two weeks'
TotalLater = TotalLater + amount
amount = (amount + 10)/2
elif key_resp_4.keys in ['', [], None]:
feedback = 'You did not make a choice. No reward given.'
amount = amount
The "amount" variable generates a numeric value, which is updated based on a left or right response. "TotalNow" and "TotalLater" keep track of the total points earned for each condition and are displayed in the next screen. These variables are working just fine.
My problem lies within the feedback variable. I've run through the script quite a few times to better understand what is happening. For most of the trials (though not all)--regardless of whether or not I make a key press--the feedback screen prints the message designated for a non response: "You did not make a choice..." Here's the strange part, though. On the feedback screen, the "TotalNow"/"TotalLater" variables display point values indicating that I DID make a key response, even though the "feedback" text variable reports that I didn't. Further, the next trial shows the updated "amount" variable correctly.
Therefore, there seems to be some disconnect between the key response and the result shown by the "feedback" variable in the next routine. I suspect that the key response may be lagging. I suspect this because I have found that I am able to make two key responses in one trial (as evidenced by extra points appearing in the point total shown in the next routine). I have set the key response component to force the end of the routine, store only the first key, and discard any previous responses. Even with these settings, though, it is possible to make two responses.
Does anybody have ideas as to why these events are occurring? I'm puzzled by this myself. Any help is much appreciated.
-Ben
This is a rather unsatisfactory answer, but I resolved the issue first by following Jonas's advice and then by removing an extraneous loop that became obsolete through the programming of the experiment. This does not specifically answer the question of why the key response was lagging, but it seems to be working well now.