I have a basic C++ program but I am getting a logic error...it is outputting both an answer for the right and wrong answer each time...Can someone take a look and see where I am going wrong....haven't done C++ in a while and it has me stuck....
I have a basic C++ program but I am getting a logic error...it is outputting both an answer for the right and wrong answer each time...Can someone take a look and see where I am going wrong....haven't done C++ in a while and it has me stuck....
CCNA looking for an opportunity
#include <iostream>
#include <cstdlib>
#include <conio.h>
#include <stdio.h>
using namespace std;
int application(int n, int n1);
int number1Selection();
int number2Selection();
int main()
{
char response;
int number, number1, num3, num4, num5, num6, level1Count, level2Count, level3Count, level1Percent, level2Percent;
printf("Welcome to Level 1 of our Computer Assisted Instructions for Mathematics.");
for (int count1 = 1; count1 <= 10; ++count1)
{
number = number1Selection();
number1 = number1Selection();
level1Count = application(number, number1);
}
level1Percent = level1Count * 100 / 10;
if (level1Percent > 70)
{
printf("\nCongratulations. You have been promoted to level 2!");
printf("\nWelcome to Level 2 of our Computer Assisted Instructions for Mathematics.");
for (int count2 = 1; count2 <= 10; count2++)
{
num3 = number2Selection();
num4 = number1Selection();
level2Count = application(num3, num4);
}
level2Percent = level2Count * 100 /10;
}
else
printf("Please seek help from your administrator before continuing.");
if (level2Percent > 80)
{
printf("\nCongratulations. You have been promoted to level 3!");
printf("\nWelcome to Level 3 of our Computer Assisted Instructions for Mathematics.");
for (int count3 = 1; count3 <= 10; count3++)
{
num5 = number2Selection();
num6 = number2Selection();
level3Count = application(num5, num6);
}
}
else
printf("Please seek help from your administrator before continuing.");
getch();
return 0;
}
int number1Selection()
{
return ((rand() % 9) + 1);
}
int number2Selection()
{
return ((rand() % 99) + 1);
}
int application (int num1, int num2)
{
int resultResponse = (rand() % 4) + 1;
int result , answer, levelcount;
char option;
printf("\nDo you want to add, multiply, subtract or divide? \na for addition\ns for subtraction\nm for multiplication\nd for division\n");
scanf("%c", &option);
switch (option)
{
case ('A'): case ('a'):
{
result = num1 + num2;
printf("How much is %d + %d\n",num1,num2);
scanf("%d", &answer);
break;
}
case ('S'): case ('s'):
{
if (num1 < num2)
{
result = num2 - num1;
printf("How much is %d - %d\n",num2, num1);
scanf("%d", &answer);
}
else
{
result = num1 - num2;
printf("How much is %d - %d\n",num1, num2);
scanf("%d", &answer);
}
break;
}
case ('D') : case ('d'):
{
if (num1 < num2)
{
result = num2 / num1;
printf("How much is %d / %d\n",num2, num1);
scanf("%d", &answer);
}
else
{
result = num1 / num2;
printf("How much is %d / %d\n",num1, num2);
scanf("%d", &answer);
}
break;
}
case ('M') : case ('m'):
{
result = num1 * num2;
printf("How much is %d * %d\n",num1, num2);
scanf("%d", &answer);
break;
}
default:
printf("Invalid response! Please try again.");
}
if (result == answer)
{
levelcount++;
switch (resultResponse)
{
case (1):
{
printf("Very good!!");
break;
}
case (2):
{
printf("Keep it up!!");
break;
}
case (3):
{
printf("Nice job!!");
break;
}
case (4):
{
printf("Excellent");
break;
}
}
}
else if (result != answer)
{
switch (resultResponse)
{
case (1):
{
printf("No. Please try again");
break;
}
case (2):
{
printf("Wrong try once more");
break;
}
case (3):
{
printf("Don't give up");
break;
}
case (4):
{
printf("Sorry!! Keep trying");
break;
}
}
}
return levelcount;
}
CCNA looking for an opportunity
It would have been nice if you had used the code tag... it makes reading codes a lot easier.
When I get some time I'll go though this and see if I can find the problem.
.:] ^ [:..:] Game IDs: xfire_ropy | BC:BC2_ropy | BC: 2142_ropy29 | BF3_ | steam_ropy09 | LoL_ropy09 | Origin_ropy29 [:.
Please include also what your desire output should be and also the test values you used.
Thank you
On the road to success when meet up on obstacles never change your decision to go but your direction to get there
digi: 876-897-9362
IM: balrick@hotmail.com
It's ok...I think i sorted it out....Thanks anyway
CCNA looking for an opportunity