You are viewing our Forum Archives. To view or take place in current topics click here.
Help With a Program [TurboC++]
Posted:

Help With a Program [TurboC++]Posted:

Taylor
  • E3 2017
Status: Offline
Joined: Apr 30, 201410Year Member
Posts: 5,962
Reputation Power: 15122
Status: Offline
Joined: Apr 30, 201410Year Member
Posts: 5,962
Reputation Power: 15122
As the title states, I need help with my program, the issue is related to branching and looping.

My program is a simple 10 question addition problem quiz, for second grade students. Using randomize, it randomly generates the numbers. The program tells you what question you are on, and when you are done it tells you how many you got right, out of 10.

I have it so that whenever the user finishes the quiz/program and sees the message, You got 9 out of 10 correct! they will receive a message below that one, mine is, Good job, but it could be better!);

My problem:

Say the user gets 0 correct out of 10, I dont want the program to say Good job. Also, if the user gets 10 correct out of 10, I dont want the program to say ...but it could be better!

At the moment, with my existing code the program does the following upon execution;

Program prompts user(s) to enter 1 for Addition Quiz
Program gives the user(s) 10 randomized addition problems
Program tells user(s) how many questions were correct, out of 10.
Program displays: Good job, but it could be better

*This is when the user would hit ENTER to close the program, but. It then replaces the text, Good job, but it could be better with the new text, Amazing!.


How do I fix this so that only Amazing! comes up whenever the user(s) gets 10 out of 10?


How (with my existing code) would I be able to do this, Im not sure exactly what I need to put it for it to say these things, I know it would look something like this;

if(total==10)
cprintf(AMAZING, You got 10 out of 10 correct!);



#include <iostream.h>
#include <conio.h>
#include <dos.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <iomanip.h>
#include <stdio.h>

void Add()

int total, chc, Qs;
char chc2;

main()
{
randomize();
total0;
Qs=0;
   do{
do{
   textbackground(BLACK);
   textcolor(LIGHTCYAN);
   clrscr();
   gotoxy(1,1);
   cprintf(You have %d/%d.,total, Qs);
   gotoxy(35,1);
   cprintf(Addition = 1);
   gotoxy(35,5);
   cprintf(End=5);
   gotoxy(35,9);
   cprintf(:);
   cin>>chc;

   if(chc==1)
   {
   Add();
   }
   if(chc==5)
   {
   clrscr();
   gotoxy(25,12);
   cprintf(Are you sure you want to quit? Y or N: );
   cin>>chc2;
   }
   
   }while(chc!=5);
   }while(chc2==n||chc2==N);
return 0;
}

void Add()
{
   textbackground(BLACK);
   textcolor(LIGHTCYAN);
   clrscr();
   int g, num1, num2. ans, useans, right;

   right=0
   for(g=1;g<=10;g=g+1)

   clrscr();
   gotoxy(35,1);
   cprintf(Question %d, g);
   num1=random(11);
   num2=random(11);
   ans=num1+num2;
   gotoxy(39,11);
   cprintf(%d, num1);
   gotoxy(38,12);
   cprintf(+%d, num2);
   gotoxy(39,13);
   cin>>useans;

   if(useans==ans)
      {
   right=right+1;
   clrscr();
   gotoxy(35,12);
   cprintf(Good job!);
   delay(800);
      }
   if(useans!=ans)
      {
   clrscr();
   gotoxy(35,12);
   cprintf(Sorry, thats wrong! The answer is %d., ans);
   
      }

      }

   textbackground(BLACK);
   textcolor(LIGHTCYAN);
   clrscr();

   gotoxy(25,1);
   cprintf(You got %d out of 10 correct!, right);
   gotoxy(25,3);
   cprintf(Good job, but it could be better!);
   getch();
   total=total+right;
   Qs=Qs+10;

      {

      }

   gotoxy(25,1);
   cprintf(You got %d out of 10 correct!, right);
   gotoxy(25,3);
   cprintf(AMAZING!);
   getch();
   total=total+right;
   Qs=Qs+10;
   }
   



Here is my code in the program, TCLite. Not sure if this helps or not :/


[ Register or Signin to view external links. ]
[ Register or Signin to view external links. ]
[ Register or Signin to view external links. ]


I would GREATLY appreciate it if anybody would be able to help me with this, I am still new to programming and still learning to do some technical things.

The following 1 user thanked Taylor for this useful post:

Foot_Fetish (10-27-2015)
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.