Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

NEED 2 RUN C CODE UNDER LINUX ENVIRONMENT

Hi friends...
i need to work the following code in linux. Its running fine under windows environment bur i need to have the exact output under linux environment...can any1 please fix that code for me so that it displays the exact output under linux environment...I need it urgently friends!!!
can somebody help...
Thanks in advance...
Sukh
/*This program deals with CAI (Computer Aided Instruction) which is often used to both develop and consolidate skills. This programming exercise involves the presentation of arithmetic questions to the user and provides varied feedback. The user h
ave the option to choose a range of numbers to be used in the calculations; for example: single digit numbers or numbers up to 20.
*/
/*Author: Sukhminder Singh*/
/*Ver: cp728-1.0*/
/*Student ID: 2450362*/
#include

void getGrade(char);
main()
{
/*declarations*/
int i,x,j,k,min,max,option,grade=0,total=0,totalques,range,true=0,false=0,reply,reply1;
int choice1;
char choice;
clrscr();
printf("******************************************************************************");
printf("
******************************************************************************");
printf("
======================CHECK YOUR MATHEMATICAL SKILLS==========================");
printf("
******************************************************************************");
printf("
******************************************************************************");
printf("

PLEASE ENTER A RANGE OF NUMBERS TO BE USED IN CALCULATIONS:");/*prompting the user for Range*/
printf("
Please Enter from -50 to +50:
");
min=-51;
do/*First do while*/
{
do
{
printf("From What Number:");scanf("%d",&min);/*inputting minimum range*/
}while(min<-50);/*end of min do-while*/
max=51;
do
{
printf("Till What Number Please...");scanf("%d",&max);/*inputting maximum range*/
}while(max>50);/*end of max do-while*/
}while(max<=min);/*end of First do-while*/
range=max-min+1;
do/*main do-while loop*/
{

x=rand() %10;/*using random function to randomise the switch case choices*/
clrscr();
switch (x)/*start of switch case*/
{
case 0:
case 1:
case 2:
case 3: j=random(range)+min;/*calculating the random value for inputing to the question*/
k=random(range)+min;
printf("
What is %d times %d ? ",j,k);
scanf("%d",&reply);/*asking for the user reply*/
if(reply == (j*k))/*comparing the value of reply from user with the actual answer*/
{
true++;/*incrementing the value if true*/
getGrade('t');/*calling function for Display Prompts*/
}
else
{
false++;/*incremeting the variable if user reply is false*/
getGrade('f');/*calling the function for Display Prompts*/
}
total++;/*keeping record of the total questions asked*/
break;/*breaking out of the case*/
case 4:
case 5:
case 6: j=random(range)+min;
k=random(range)+min;
printf("
What is %d plus %d ? ",j,k);
scanf("%d",&reply);
if(reply == (j+k))
{
true++;
getGrade('t');
}
else
{
false++;
getGrade('f');
}
total++;
break;
case 7:
case 8:
case 9: j=random(range)+min;
k=random(range)+min;
printf("
What is %d minus %d ? ",j,k);
scanf("%d",&reply);
if(reply == (j-k))
{
true++;
getGrade('t');
}


else
{
false++;
getGrade('f');
}
total++;
break;
case 10:
case 11:
case 12: j=random(range)+min;
k=random(range)+min;
printf("
What is %d divided by %d ?",j,k);
scanf("%d",&reply);
if(reply ==(j/k))
{
true++;
getGrade('t');
}
else
{
false++;
getGrade('f');
}
total++;
break;
}/*end of switch-case*/
printf("
The Number of Correct Answers so far is %d",true);/*Displaying the no of True Answers*/
printf("
The Number of Incorrect Answers so far is %d",false);/*Displaying the no of Flase Answers*/
printf("
Total questions asked %d",total);/*Displaying the number of Total Questions asked*/
printf("

Press q to quit or any other key to continue....
");
choice=getche();

}while((choice != 'q'));/*end of first do-while*/

grade = ((float)true / total * 100);/*Calculating the Grade according to the Correct Answers from Total*/

if(grade>=80)/*Start of If Condition*/
printf("
Your Grade is: A");
else if(grade>=70)
printf("
Your Grade is: B");
else if(grade>=60)
printf("
Your Grade is: C");
else if(grade>=50)
printf("
Your Grade is: D");
else if(grade>=40)
printf("
Your Grade is: E");
else/*end of If Condition*/
printf("
Your grade is Below 39");
getch();
return 0;/*successful comletion of program statements*/
}
void getGrade(char ch)/*Function to Display the Prompts if user reply is true or false*/
{
int res;
res=rand()%4+1;
if(ch=='t')/*Checking if the user reply is true*/
{
switch(res)/*start of switch statement*/
{
case 1: printf("

Excellent!!!");
break;
case 2: printf("

Very Good!!!");
break;
case 3: printf("

Nice Work!!!");
break;
case 4: printf("

Keep Up the Good Work!!");
break;

}/*end of switch case*/
}
else/*if the user reply is false*/
{
switch(res)/*start of switch case*/
{
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("

No. Keep Trying!!");
break;
}/*end of switch case*/
}/*end of if condition*/
}/*end of function*/


Comments

  • prasunprasun Member Posts: 46
    Instead of such a big conversion can you specify where exactly are you facing problem!!!
  • sukhmindersukhminder Member Posts: 19
    : Instead of such a big conversion can you specify where exactly are you facing problem!!!
    :
    hi prasun...i want the exact output of this code in linux using gcc. basically the getche() at the end of the while loop is not working if i scanf() this variable...i want the exact output under linux as u get while compiling this code on windows...
  • athomasathomas Member Posts: 228
    Hi,

    i got bad news for you. The getche() and getch() functions do not work under Linux because they are not implemented. You need to use scanf() or write your own getch() function. This is one drawback of Linux C standard lib.

    cheers.
    Alex

    : : Instead of such a big conversion can you specify where exactly are you facing problem!!!
    : :
    : hi prasun...i want the exact output of this code in linux using gcc. basically the getche() at the end of the while loop is not working if i scanf() this variable...i want the exact output under linux as u get while compiling this code on windows...
    :

  • job4csejob4cse Member Posts: 29
    : Hi,
    :
    : i got bad news for you. The getche() and getch() functions do not work under Linux because they are not implemented. You need to use scanf() or write your own getch() function. This is one drawback of Linux C standard lib.
    :
    : cheers.
    : Alex
    :
    : : : Instead of such a big conversion can you specify where exactly are you facing problem!!!
    : : :
    : : hi prasun...i want the exact output of this code in linux using gcc. basically the getche() at the end of the while loop is not working if i scanf() this variable...i want the exact output under linux as u get while compiling this code on windows...
    : :
    :
    :

    Hi,
    However u can use ncurses library in which case u have getch.

    Regards,
    JOB
  • rajeshrdrajeshrd Member Posts: 1
    Hi.
    u can try getchar();

    : : Hi,
    : :
    : : i got bad news for you. The getche() and getch() functions do not work under Linux because they are not implemented. You need to use scanf() or write your own getch() function. This is one drawback of Linux C standard lib.
    : :
    : : cheers.
    : : Alex
    : :
    : : : : Instead of such a big conversion can you specify where exactly are you facing problem!!!
    : : : :
    : : : hi prasun...i want the exact output of this code in linux using gcc. basically the getche() at the end of the while loop is not working if i scanf() this variable...i want the exact output under linux as u get while compiling this code on windows...
    : : :
    : :
    : :
    :
    : Hi,
    : However u can use ncurses library in which case u have getch.
    :
    : Regards,
    : JOB
    :

Sign In or Register to comment.