Borland C++ 5.02 cout not showing on the console window -
i'm sorry newbie question, tried make program using borland 5.02, reason cout in if (stat) isn't showing on console window when write married. don't know what's wrong , i've been stuck hours. please me
#include <stdio.h> #include <conio.h> #include <iostream.h> int main() { int nip, gol, gp, ti, ta, ja, tg ; char nm[20], stat[10] ; cout << "id number : " ; cin >> nip ; cout << "name : " ; cin >> nm ; cout << "faction : " ; cin >> gol ; if (gol == 1) { gp = 1500000 ; } else if (gol == 2) { gp = 2000000 ; } else { gp = 2500000 ; } cout << "status : " ; gets (stat) ; if (stat == "married" || stat == "married") { cout << "number of children : " << endl ; cin >> ja ; ti = 0.05 * gp ; if (ja <= 3) { ta = 0.02 * gp * ja ; } else { ta = 0.02 * gp * 3 ; } } else { ti = 0 ; ta = 0 ; } tg = gp + ti+ ta ; cout << endl << "-results-" << endl ; cout << "your gp: " << gp << endl ; cout << "your ti: " << ti << endl ; cout << "your ta: " << ta << endl ; cout << "your tg: " << tg << endl ; getch () ; }
update : have tried change gets(stat) ;
cin >> stat ;
before doesn't seem have effect. program looked when run them
id number : 0123141421
name : vykmon
faction : 1
status : married (here problem)
-results-
your gp: 1500000
your ti: 0
your ta: 0
your tg: 1500000
even though have write married on status, cout << "number of children : " << endl ;
didn't show on console window. if if (stat == "married" || stat == "married")
aren't working, , "status: married" count
else { ti = 0 ; ta = 0 ; }
stat == "married"
work in standard c++ if stat
std::string
.
however, it's array of char
, , means you're comparing 2 pointers. because c++ doesn't support direct comparison of arrays. each of 2 array expressions decay pointer first item.
and these pointers guaranteed different.
note 1: borland c++ 5.02 sounds mid 1990's, before first c++ standard. there host of free modern compilers. 3 known g++, clang , visual c++ (the latter available pc platform).
note 2: recall std::string
in borland c++ totally botched. if using std::string
doesn't work, consider using strcmp
compare c strings (like arrays have).
note 3: in standard c++ (since first standard in 1998) there no <iostream.h>
header. instead include <iostream>
, , possibly add using namespace std;
. or appropriate using
directives, or qualifications of names cout
, endl
, i.e. writing std::cout
, std::endl
.
in other news:
by reserving shoutcase names macros, can ease code reading experience significantly, , avoid unintended text substitutions boot. not mention conforming common convention this.
by using
getline
instead of>>
, program can read name space in it. however, works nicely when input buffer empty (sincegetline
doesn't skip whitespace). so, it's consider, can involve work.
Comments
Post a Comment