C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old April 9th, 2002, 08:28 AM
Fenris Fenris is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Norwich, UK
Posts: 2 Fenris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Exclamation Maths program. Very cheeky help request...

Hi,

I desperately need some help! I'm currently a mature student studying computing at night school. The module that we've just finished was based primarily on programming in C, I sat the test at the end of the term unprepared and managed to somehow wangle a distinction! However, due to getting totally stumped and being swamped at the time as well, I did not complete the assignment and as such I will fail the module. I've been granted a week (until Monday 15th) to get something in.

What I'm looking for is someone to sacrifice their ethics in return for my unending thanks! The program is relatively simple: It's a basic maths testing program. It should have a menu system asking whether one wants to answer addition, subtraction or multiplication questions (and possibly division). It should then ask a series of ten questions on the chosen subject using randomly generated numbers, and respond with a selection of positive and negative phrases (i.e. well done! or you're crap!) depending on how you answer. If you are incorrect, you should have two more chances to get it right. The program should keep a tally of the scores and when the ten questions have been answered it needs to display the number of questions passed, possibly as a percentage.

The earliest I can get started on this will be Friday. What I am hoping (and I appreciate it's reaching a bit! for is either someone who is so good they can knock this up in a few minutes for me, OR someone who has done something similar to this already and doesn't mind me "borrowing" vast chunks of it, or failing that anything that could save my arse at all...!

Mail me at URL

Please, please, please help! Many thanks.

Reply With Quote
  #2  
Old April 10th, 2002, 06:14 PM
jstn jstn is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Posts: 0 jstn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to jstn
if you were to request such a program to me via email i can send you a similar progam which you can tailer to suit your needs.



-jstn

Reply With Quote
  #3  
Old April 12th, 2002, 11:02 AM
The Ostrich The Ostrich is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2002
Location: Oxford, UK
Posts: 31 The Ostrich User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
I would imagine something like:

Code:
#include <stdlib.h>
#include <stdio.h>

int main()
{
    int count;
    int NumberCorrect;
    int NumQuestions;
    int Operator;
    int val1, val2, result, guess;
    
    do
    {
        printf("Enter the number of questions: ");
        fflush(stdout);
        scanf("%d", &NumQuesitons);
        if(NumQuestions > 0 && NumQuestions <= 20) break;
        printf("Please enter a number between 1 and 20!\n");
    }
    while(1);

    do
    {
        printf("Select one of the following and press enter:\n");
        printf("  1: Addition\n");
        printf("  2: Subtraction\n");
        printf("  3: Multiplication\n");
        scanf("%d", Operator);
        if(Operator > 0 && Operator <= 3) break;
        printf("Please select an option (1, 2 or 3)!\n");
    }
    while(1);

    NumberCorrect = 0;
    for(count = 0; count < NumQuestions; count++)
    {
        val1 = rand() % 100;
        val2 = rand() % 100;
        printf("What is val1 ");
        if(Operator == 1) printf("+");
        else if(Operator == 2) printf("-");
        else if(Operator == 3) printf("*");
        printf(" val2?: ");
        fflush(stdout);
        scanf("%d", &guess);
        if(Operator == 1) result = val1 + val2;
        if(Operator == 2) result = val1 - val2;
        if(Operator == 3) result = val1 * val2;
        if(result == guess)
        {
            printf("Correct!\n\n");
            NumberCorrect++;
        }
        else
        {
             prinf("Wrong!\n\n");
        }
    }

     printf("-- END OF TEST --\n");
     printf("Your score = %d/%d\n", NumberCorrect, NumQuestions);

}

Reply With Quote
  #4  
Old April 14th, 2002, 07:01 AM
Fenris Fenris is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Norwich, UK
Posts: 2 Fenris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Talking Cheers

Huge thanks for the two of you getting back to me, I think I'm going to butcher and amalgamate the two and come out with something pretty good!

You're both stars! Cheers again...

Reply With Quote
  #5  
Old April 15th, 2002, 11:23 AM
Fenris Fenris is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Norwich, UK
Posts: 2 Fenris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Code

Just in case any one is interested, this is the code that I came up with in the end. There was a lot more I could have done, but the tutor has told me he won't mark me any higher than a pass because it's late Anyway, it's done and dusted now...

//-----------------------------------------------------------------------------|
// Mathematics Computer Aided Learning Program |
// |
// Written by Fenris - April 2002 |
//-----------------------------------------------------------------------------|

#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <conio.h>

void correct(int);
void wrong(int);

main()
{
char choice;
int ran1, ran2, solution, input, ans, count, corans, countin;

printf("\t---------------------------------------------------------------------------\n");
printf("\t| Welcome to the Maths Computer Aided Learning Program! |\n");
printf("\t---------------------------------------------------------------------------\n\n");

printf("Please select an option from the menu below:\n\n");
printf("Please enter A for addition, S for subtraction,\n");
printf("M for multiplication or any other key to quit.\n\n\n");

choice = getchar();

switch(choice)
{
case 'a':
case 'A': printf("\nYou selected addition.\n\n"); break;
case 's':
case 'S': printf("\nYou selected subtraction.\n\n"); break;
case 'm':
case 'M': printf("\nYou selected multiplication.\n\n"); break;
default: printf("\nGoodbye! (Press any key to quit).");
fflush(stdin);
getch();
exit (0);
}

corans = 0;
for(count = 0; count < 10; count++)
{

// Could not get the randomize and random commands to work on this
// compiler. This works okay though.
srand(time(NULL));
ran1 = 1 + (rand() % 10);
ran2 = 1 + (rand() % 10);

if((choice == 'a') || (choice == 'A')) solution = ran1 + ran2;
else if((choice == 's') || (choice == 'S')) solution = ran1 - ran2;
else if((choice == 'm') || (choice == 'M')) solution = ran1 * ran2;

printf("What is %d ", ran1);
if((choice == 'a') || (choice == 'A')) printf("+");
else if((choice == 's') || (choice == 'S')) printf("-");
else if((choice == 'm') || (choice == 'M')) printf("*");
printf(" %d\t\t\t\t", ran2);
scanf("%d", &input);

if(input == solution)
{
corans++;
ans = 1 + (rand() % 4);
correct(ans);
}
else
{
ans = 1 + (rand() % 4);
wrong(ans);
countin = 0;
while((countin < 2) && (input != solution))
{
ans = 1 + (rand() % 4);
printf("Try again...");
printf("\t\t\t\t");
scanf("%d", &input);
if(input == solution)
{
corans++;
ans = 1 + (rand() % 4);
correct(ans);
}
else
{
wrong(ans);
countin++;
}
}
}

}

printf("\n\t-- END OF TEST --\n\n");
printf("You scored = %d out of 10\n\n", corans);
if (corans > 7) printf("Well done, you passed!\n");
else printf("You really are thick. Go and shoot yourself.\n");
printf("\nPress any key to continue");
fflush(stdin);
getch();

return 0;
}

//------------------------------------------------------------------------------
void correct(ans)
{
switch(ans)
{
case 1:
printf("\nVery good!\n\n");
break;
case 2:
printf("\nNice one!\n\n");
break;
case 3:
printf("\nHurrah!\n\n");
break;
case 4:
printf("\nKeep up the good work!\n\n");
}
}
//------------------------------------------------------------------------------
void wrong(ans)
{
switch(ans)
{
case 1:
printf("\nNo, idiot!\n\n");
break;
case 2:
printf("\nAre your parents brother and sister?\n\n");
break;
case 3:
printf("\nRetard!\n\n");
break;
case 4:
printf("\nAre you stupid?\n\n");
}
}

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Maths program. Very cheeky help request...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

IBM developerWorks




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway