If function problem
Jan 9, 2016 at 2:49pm UTC
My question is how do i make the if to check if the input is lower than 90 to "Fail" and exit the code and if its greater than 90 to continue the inputs. Lines 94 - 104 Thanks!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
#include <iostream>
#include <fstream>
#include<iomanip>
#include <cstdlib>
#include <string>
using namespace std;
class Kursist
{
//private
string ime;
string familia;
int listovka;
int drive1;
int drive2;
public :
Kursist(string name, string lname, int test, int driving1, int driving2)
{
ime=name;
familia=lname;
listovka=test;
drive1=driving1;
drive2=driving2;
}
Kursist() {}
~Kursist() {}
string GetName()
{
return ime;
}
string GetLname()
{
return familia ;
}
int GetTest()
{
return listovka;
}
int GetDriving1()
{
return drive1;
}
int GetDriving2()
{
return drive2;
}
};
void outputLine( Kursist );
int main( )
{
int i;
Kursist kursist[3];
string name;
string lname;
int test;
int driving1;
int driving2;
cout << "Enter the name, family and results.\n" ;
for (i=0; i<3; i++)
{
cout <<"Ime: \n" ;
cin >> name;
cout <<"Family: \n" ;
cin >> lname;
cout <<"Test: \n" ;
cin >> test;
if ( test < 90 )
{
cout<<"Fail!\n" ;
}
else ( test >= 90)
{
cout<<"Sucssess\n" ;
}
cout <<"Driving1: \n" ;
cin >> driving1;
cout <<"Driving2: \n" ;
cin >> driving2;
Kursist akursist(name, lname, test, driving1, driving2);
kursist[i]=akursist;
}
ofstream outKursistFile;
outKursistFile.open( "kursist18.dat" );
{
if ( !outKursistFile )
cerr << "File could not be opened" << endl;
}
for (i=0; i<3; i++)
{
outKursistFile << kursist[i].GetName() << ' ' << kursist[i].GetLname()<< ' ' <<kursist[i].GetTest()<< ' ' << kursist[i].GetDriving1() << ' ' <<kursist[i].GetTest()<< '\n' ;
}
outKursistFile.close();
return 0;
}
void outputLine( Kursist kursist )
{
cout << setiosflags( ios::left ) << setw( 10 ) << kursist.GetName() << setw( 13 ) << kursist.GetLname() <<setw( 7 ) << setprecision( 2 )<< resetiosflags( ios::left )<<kursist.GetTest()<< ' ' <<kursist.GetDriving1()<< ' ' <<kursist.GetDriving2()<< '\n' ;
}
Jan 9, 2016 at 2:58pm UTC
if ( test < 90 )
{
cout<<"Fail!\n";
exit(0);
}
use thz & c
Jan 9, 2016 at 3:01pm UTC
Thanks! <3
Topic archived. No new replies allowed.