Mar 14, 2012 at 2:09am UTC
Plz tell me what is lacking ... it will not display...
# include <windows.h>
# include <iostream>
# include <string>
# include <conio.h>
# include <stdio.h>
using namespace std;
void gotoXY(int x, int y);
char num1[1000];
char num2[1000];
bool n = true;
int a, opt1, opt2;
char c, opt,t;
int main () {
do {
// print the box and the numbers
gotoXY(0,0); cout << char(201);
gotoXY(40,0); cout << char(187);
for(int i=1; i<40; i++)
{
gotoXY(i,0); cout << char(205);
gotoXY(i,16); cout << char(205);
}
gotoXY(0,16); cout << char(200);
gotoXY(40,16); cout << char(188);
for(int j=1; j<16; j++)
{
gotoXY(0,j); cout << char(186);
gotoXY(40,j); cout << char(186);
}
for(int k=1; k<40; k++)
{
gotoXY(k,3); cout << char(205);
}
gotoXY(1,4);
cout << "7 \t 8 \t 9 \t * \n";
gotoXY(1,6);
cout << "4 \t 5 \t 6 \t / \n";
gotoXY(1,8);
cout << "1 \t 2 \t 3 \t . \n";
gotoXY(1,10);
cout << "0 \t + \t - \t = \n";
gotoXY(1, 12);
return 0;
gotoXY(2,2); cin >> num1;
gotoXY(2,3); cin >> opt;
gotoXY(2,4); cin >> num2;
if((c-'0') >= 0 && (c-'0') <= 1000)
{
if(a <1000)
{
if(n==true)
{
num1[a]=c;
gotoXY(2,2); cout << num1;
}
else
{
if((c-'0') >= 0 && (c-'0') <= 1000)
{
if(a <1000)
{
if(n==true)
{
num2[a]=c;
gotoXY(2,4); cout << num2;
}
}
}
}
a++;
}
}
else if(c=='+' || c=='-' || c=='*' || c=='/')
switch(opt)
{
case '+': opt1 + opt2;
gotoXY(2,3); cout << "+";
break;
case '-': opt1 - opt2;
gotoXY(2,3); cout << "-";
break;
case '*': opt1 * opt2;
gotoXY(2,3); cout << "*";
break;
case '/': opt1 / opt2;
gotoXY(2,3);cout << "/";
break;
}
else if(c=='=')
{
if(opt=='+')
{
gotoXY(2,6); cout << opt1 + opt2;
}
else if(opt=='-')
{
gotoXY(2,6); cout << opt1 - opt2;
}
else if(opt=='*')
{
gotoXY(2,6); cout << opt1 * opt2;
}
else if(opt=='/')
{
if(num2==0)
{
gotoXY(2,6); cout << "ERROR!";
}
else
{
gotoXY(2,6); cout << opt1 / opt2;
}
}
}
else if(c==27)
{
gotoXY(2,2); cout << "______________";
}
else
{
gotoXY(2,2); cout << "ERROR!";
}
}while(c!=t);
gotoXY(2,2); cout << "_______________";
}
void gotoXY(int x, int y)
{
//Initialize the coordinates
COORD coord = {x, y};
//Set the position
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
return;
}
Mar 14, 2012 at 10:19pm UTC
try using code /code tags, and indentation, that will fix 90% of your headache, and 100% of mine.
what won't display?
Mar 15, 2012 at 3:28am UTC
when I will compile it... it will just display a sec and then exit?
Last edited on Mar 15, 2012 at 3:30am UTC
Mar 15, 2012 at 8:52am UTC
Thank you, I will try reading this one........... hope I can find the answer........
I only understand a little of C++.
Mar 16, 2012 at 7:54am UTC
I'm sorry, I dont really understand where to put the other codes for it to run. I try compiling this in dev c++, but it will just flash......... I can't do the calculations because it will just flash...........plz.........help
Last edited on Mar 16, 2012 at 8:11am UTC
Mar 16, 2012 at 10:35am UTC
use getch(); function at the end of the main(). it will halt the screen.