Click here to Skip to main content
15,891,738 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
#include <iostream>
#include <stdlib.h>
#include <string>
#include <conio.h>
#include <fstream>
#include <time.h>
using namespace std;

string questions[50];
string str;

class contest
{

private:
  int roll;
  float x;
  char name[50];
  char s[100],ans;

 public:
 contest()
 { x=0; }
 void init();
 void define();
 void display();
 };
 void  contest :: define()

 {
ifstream in;
  char a;
  int i=0;

  in.open("questions.txt");
  while(in.eof()==0)
 {
 in.getline(s,100);
 cout<<endl<<s;
if(i==5)
{
in.get(a);
cout<<"\nans:";
 cin>>ans;
i=-1;
if(ans==a)
   {
   x=x+5;
   cout<<" *Your ans  correct.\n";
   }
 else
   {
   if(x>0)
    x=x-2.5;
   cout<<" # Wrong ans.\n";
   }
 }
  i++;
  }
 in.close();
 }
  void contest :: init()
   {
 cout<<"\t\t\t   Student Name:";
 cin>>name;
 cout<<"\t\t\t   Index Number:";
 cin>>roll;
   }
 void contest :: display()
   {
 cout<<"\n **Result:\n";
 cout<<"\t"<<name<<" you got total "<<x<<" marks, out of 50.\n";
   }

 int main()
{
  clrscr();
  contest r;
  cout<<"      \t\t\t     QUIZ    \t      Total Marks:50\n\n";
  r.init();
  cout<<"\t*5 marks per Ques(half negative marking for wrong ans)";
   L:
  cout<<"\n\n\tselect your choice:\n"
    <<"\n\tTo start Quiz Press 1"
    <<"\n\tTo quit Press 0        :";
   int c;
   cin>>c;
   switch(c)
   {
   case 1:
    r.define();
    r.display();
    break;
   case 0:
    exit(1);
   default:
    cout<<"invalid choice!";
    goto L;
   }
   getch();
   }
Posted
Updated 23-Nov-20 22:16pm
v3
Comments
joshrduncan2012 21-Nov-13 12:23pm    
Please format your code using the <pre> tags.
Ron Beyer 21-Nov-13 13:15pm    
What compiler are you using?

clrscr is a Borland TurboC++ non-standard function, and isn't present in other compilers.
In your code, I would just remove the call (since you only use it the once at the top of the Main function) and ignore the lask of "clean screen" is leaves, but there is a method I found here: http://stackoverflow.com/questions/930138/is-clrscr-a-function-in-c[^] which should work.
C++
// somewhere in the program
#DEFINE WINDOWS 1

void console_clear_screen() {
  #ifdef WINDOWS
  system("cls");
  #endif
  #ifdef LINUX
  system("clear");
  #endif
}
 
Share this answer
 
Comments
Arkorful Jnr 23-Nov-13 9:03am    
This is what i had after modifying the code [Error] ld returned 1 exit status. Actually i am a beginner so, so i sometimes have difficulty understanding some of the statements
OriginalGriff 23-Nov-13 9:38am    
Then for the moment, just take out the clrscr from your code and ignore it. You shouldn't need it anyway.
XML
#include <conio.h>
#include <math.h>
#include <stdio.h>
#include <cstdlib>
#define WINDOWS 1

void clrscr() {
  #ifdef WINDOWS
  system("cls");
  #endif
  #ifdef LINUX
  system("clear");
  #endif
}

int main(){
    int a = pow(3,2);
    clrscr();
    printf("\nMath Power Function :: %d ",a);
    getch();
    return 0;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900