• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

Repeat C program and output the scores obtained by user

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I have written a program in C language. The program is designed for primary school students in Grades 1-2. Two integers are randomly selected, the numbers are either added or subtracted to form an equation, and the students are asked to solve the equation.

Code criteria:
a. Each round of the game consists of 10 questions that are not to be repeated. 10 marks for each question. Each round of games is required to be set anew and is not have the same questions as the previous rounds.


b. Only the addition and subtraction within 100 is allowed, the sum and difference of the two numbers should not exceed the range of 100, and is not to have a negative value.


c. For each question, players have 3 chances to enter their answers. 10 points are awarded for the first correct attempt, 7 points for the second attempt, 5 points for the third attempt, zero points if all 3 attempts failed. When an incorrect answer is entered, a message should appear prompting the student to re-enter the answer. Output the correct answer if all 3 attempts are used in the form "No, the answer is X".


d. At the end of the test, a message should appear prompting the player to choose "Show results", by entering the letter "S", "Play another round", by entering the letter "P", and "Quit", by entering the letter "Q". If the player entered "S" after one round of the game, output the player's score (marks/100). If the player chooses "Show results" after multiple rounds of the game, the output should include the player's highest score/%, lowest score/%, and the average score/% of all games played. If the player enters "Q", the program ends.


e. Include fault tolerance function, a simple menu interface, necessary notes. The program should also meet the requirements of modularization and structurization.

This is my code:



Code criteria not fulfilled:

d. At the end of the test, a message should appear prompting the player to choose "Show results", by entering the letter "S", "Play another round", by entering the letter "P", and "Quit", by entering the letter "Q". If the player entered "S" after one round of the game, output the player's score (marks/100). If the player chooses "Show results" after multiple rounds of the game, the output should include the player's highest score/%, lowest score/%, and the average score/% of all games played. If the player enters "Q", the program ends.

I know I might use a while loop to repeat the program but I don't know where to place it.

Besides, I have no idea how to output the scores as required in criteria d, I have only managed to set the program to include certain words of encouragement for a designated range of scores.

Lastly, how do I include a fault tolerance function? After inputting the letter "a" into one of the equations, the program just ends. I need a message to prompt the user to input a number.

Any help would be greatly appreciated.
 
Rancher
Posts: 259
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Eve - first of all, I've added some indentation to your code to make it easier for us to read/understand it:

 
John Matthews
Rancher
Posts: 259
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Eve Wein wrote:I know I might use a while loop to repeat the program but I don't know where to place it.

That's personal choice to some extent; do you want to go right back to the 'Welcome!' message, or the 'Are you ready?...' prompt? Just make sure if you choose the latter option you include the question/answer initialization each time.

Besides, I have no idea how to output the scores as required in criteria d, I have only managed to set the program to include certain words of encouragement for a designated range of scores.

You calculate the total score, which you use to select your encouragement words. Add that to a running total which you divide by the number of rounds to get the average. Also compare it against highest and lowest values, updating the values if required.

Lastly, how do I include a fault tolerance function?

Not sure what this is asking for. Fault tolerance in the user's answer? You can get a figure for how 'wrong' the answer is by dividing the difference between the user's answer and the correct one by the correct value.

After inputting the letter "a" into one of the equations, the program just ends. I need a message to prompt the user to input a number.

That's because of the
It's expecting a number, and stops reading input when it finds a non-digit (after any initial space). So it returns before consuming the "a", and will do the same thing next time(s). (Really you should be checking the scanf() return value - only 1 means that it has successfully read in a number.)

A better approach would be to read the input into a string, then use something like strtol() to attempt to convert the string into a number. Or sscanf(), as long as you check the return value.
 
We're being followed by intergalactic spies! Quick! Take this tiny ad!
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic