473,405 Members | 2,294 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Counting Points

I'm trying to finish a program that gives a test for the
user. The test has four options to choose from,
1. addition
2. subtraction
3. multiplication
4. division.

Once the user picks one of the choices above the
program will give a specific amount of mathematical
problems using one of the choices above, for example a
user picks addition. 1 + 9 =.
When the user gets an answer right the computer saves
it as a 'point.' After the test is done his/her score is
divided by the total amount of questions asked. If the
user get's a .75 or below the computer will print " You're
score is too low, try again."
What my problem is - is that the computer only counts
one correct answer, even if there is more than one. Here
is my code with comments, if you would like a clearer
look, email me and I will send you an attachment as a text
file. Thank you for your help. And, Ofcourse, if you have
any suggestions for me go right ahead.
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;
int Random_num ( void );
int Calculation ( int );
int main()
{

unsigned int counter, // This counts how many questions
asked.
userchoice, // This is the choice the user uses to
determine the kind of mathematical sign to use.
point; // This is what counts the answers the
user gets correct.

double final_score; // This is the Score the user gets
after finishing Test.

cout << " Welcome to the Elementary Math Help. This
program will test your n/"
<< " skills in Addition, Subtraction, Multiplication, and
Division."<< endl;
cout << " Choose 1 for addition \n"
<< " Choose 2 for subtraction \n"
<< " Choose 3 for multiplication \n"
<< " Choose 4 for Division \n "
<< " or press 0 for the computer to choose \n";
cin >> userchoice;

counter = 0;

while ( counter != 5 ){
point = Calculation ( userchoice );

counter++;

}

final_score = static_cast <double> ( point ) / 5;

if ( final_score <= .75 )
cout << " You scored low, please try again. " << endl;

cout << "Your score is " << setprecision (2)
<< setiosflags ( ios :: fixed | ios :: showpoint )
<< final_score << endl;
return 0;
}
int Random_num ( void )
{
int num;
num = 1 + rand() % 9;

return num;
}
int Calculation ( int x )
{
int Choice = x,
number1,
number2,
User_answer, // This is the answer the user inputs.
point;
double R_answer; // This is the correct answer to the
question.

number1 = Random_num();
number2 = Random_num();
point = 0;
enum { add = 1, subtract, multiply, division };
switch ( Choice ){
case add:
R_answer = number1 + number2;
cout << number1 << " + " << number2 << " = ";
cin >> User_answer;
break;
case subtract:
R_answer = number1 - number2;
cout << number1 << " - " << number2 << " = ";
cin >> User_answer;
break;
case multiply:
R_answer = number1 * number2;
cout << number1 << " * " << number2 << " = ";
cin >> User_answer;
break;
case division:
R_answer = number1 / number2;
cout << number1 << " / " << number2 << " = ";
cin >> User_answer;
break;
default: cout << " Program Bug. ";
break;
}
if ( User_answer == R_answer )
point++;
return point;
}
Nov 16 '05 #1
1 919
Tr1n1x wrote:
unsigned int counter, userchoice, point;
You need to declare at least one of "counter" and "point" to double.
Otherwise when dividing the app will perform integer division.
while ( counter != 5 ){
point = Calculation ( userchoice );
Put "+=" instead of "=". Note that all local variables in the function
are precicley that: local. When the function gets out of scope so does
all local variables, such is "point", which is declared in two places.
The "point" in the function will be set to 0 every time, so increasing
it at the end of the function is pointless.
if ( User_answer == R_answer ) point++;
return point;


return ( User_answer == R_answer ) ? 1 : 0;

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Srinath Avadhanula | last post by:
Hello, I am wondering if there is a way of counting graphemes (or glyphs) in python. For example, in the following string: u'\u0915\u093e\u0915' ( or equivalently, u"\N{DEVANAGARI LETTER...
6
by: Elbert Lev | last post by:
Please correct me if I'm wrong. Python (as I understand) uses reference counting to determine when to delete the object. As soon as the object goes out of the scope it is deleted. Python does...
8
by: pembed2003 | last post by:
Hi all, As an exercise, I am trying to come up with a function to count the length of a char* string using recursion. I came up with this: int count_length(char* s){ if(s == 0) return 0;...
1
by: Tony Johansson | last post by:
Hello Experts! I reading a book called programming with design pattern revealed by Tomasz Muldner and here I read something that I don't understand completely. It says "A garbarage...
18
by: ChadDiesel | last post by:
I appreciate the help on this group. I know I've posted a lot here the last couple of weeks, but I was thrown into a database project at my work with very little Access experience. No other...
7
by: zets | last post by:
I need a macro for counting the bits in the odd positions of a given input (of any type, char, pointer, int, struct, whatever). Is there any clever way I could not think of, to do it efficiently? ...
1
by: j | last post by:
Hi, I've been trying to do line/character counts on documents that are being uploaded. As well as the "counting" I also have to remove certain sections from the file. So, firstly I was working...
4
by: aaronfude | last post by:
Hi, Please consider the following class (it's not really my class, but it's a good example for my question): class Vector { int myN; double *myX; Vector(int n) : myN(n), myX(new double) { }...
21
by: jennwilson | last post by:
Ok - So, I am back. I would like to count the number of times a specific record appears in a field from one table in my query and then use that value in the same query to calculate an average....
1
by: oec.deepak | last post by:
Hi Cn any one telll me what is Reference counting in C++.
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.