Go ahead critize and maybe just maybe congratuale on the effort made.
Go ahead critize and maybe just maybe congratuale on the effort made.
oh yeah it only goes up to four grading periods or terms.
But at the end after it prints the GPA you will need it exits because there is nothing to ask(it flashes it then exits) :/
how did you change the color of that text?
Not bad, but we can't see the source and comment on that? I promise not to burn you too badly. :D
>how did you change the color of that text?
That was done with a nonstandard Borland function called textcolor() defined in conio.h. I'm taking a wild guess, but somehow I get the feeling that I'm right.
-Prelude
I think it actually waits for the user to press any key to exit.......code yeah I'll post it.....without the formula my friend helped with he's freaked out about me posting it.....as soon as I can find it......I will. :D
>without the formula my friend helped
Formula for calculating a GPA? I've got bad news for your friend, but that formula has been around for a while now. ;)
-Prelude
maybe my conio.h is outdated??? i have MSDEV VC++ 4.0 and the conio.h included does not definde textcolor()
>maybe my conio.h is outdated???
You don't have it! I'm tired of saying that conio.h is nonstandard. Compilers don't have to include lame functions like textcolor and gotoxy, they don't have to clear the screen, they don't even have to include conio at all! So please stop asking how to change the color of your text, it doesn't matter what color the text is as long as the program works. No one cares whether your text is white or green or pink or flashing neon pastels, just get the program working and users will be happy. That's it, end of story. This rant brought to you by a very annoyed programmer.
-Prelude
actually. I DO have conio.h. so WTF r u ranting about? dont ........ me off im happy listening to rants but when u say i dont have conio.h and i do ur just bein plain stupid. now tell me without ranting. what is wrong with my version of conio.h?
[EDIT] codes off, takes up too much space [/edit]
>what is wrong with my version of conio.h?
Nothing, it works fine. I wasn't saying you don't have conio, I was saying that you don't have textcolor. Here's how it is with something nonstandard: One compiler will have a function, but that function probably will not be on another compiler, the person who writes the compiler decides what nonstandard stuff to put in. Borland is full of nonstandard functions, but MSVC++ only has these:
_cgets(char *);
_cprintf(const char *, ...);
_cputs(const char *);
_cscanf(const char *, ...);
_getch(void);
_getche(void);
_inp(unsigned short);
_inpw(unsigned short);
_inpd(unsigned short);
_kbhit(void);
_outp(unsigned short, int);
_outpw(unsigned short, unsigned short);
_outpd(unsigned short, unsigned long);
_putch(int);
_ungetch(int);
/* Non-ANSI names for compatibility */
cgets(char *);
cprintf(const char *, ...);
cputs(const char *);
cscanf(const char *, ...);
inp(unsigned short);
inpw(unsigned short);
getch(void);
getche(void);
kbhit(void);
outp(unsigned short, int);
outpw(unsigned short, unsigned short);
putch(int);
ungetch(int);
That's it, nothing else.
-Prelude
thanks. do you have the textcolor() code or know where to get it? so i could include it into my conio.h of course! also liek the backdrop for text and clear screen and other goodies wold be nice too ^_^ ty :P
This might have been made shorter with Function pointers but I am just starting so that was a litte hard.
just download DevC++ it should have it.....that's what I used to compile it.
could ya do me a favor plz? go into ur conio.h and place the code here? thx ^_^
Not Sure how "legal" this is, but this is DevC++, if anything blame Denethor2000 :D :D
thx... whenever I try to use em in mine it gives me an unresolved external symbol error :(
>go into ur conio.h and place the code here?
The chances of that working aren't very good and the chances of your compiler choking and not letting you compile at all are pretty good. You'd be better off just going with Windows functions.
-PreludeCode:#include <iostream>
#include <windows.h>
using namespace std;
int main ( void )
{
HANDLE h;
h = GetStdHandle ( STD_OUTPUT_HANDLE );
SetConsoleTextAttribute ( h, FOREGROUND_RED | FOREGROUND_GREEN );
cout<<"My ";
SetConsoleTextAttribute ( h, FOREGROUND_RED );
cout<<"next ";
SetConsoleTextAttribute ( h, FOREGROUND_GREEN );
cout<<"rant ";
SetConsoleTextAttribute ( h, FOREGROUND_INTENSITY | FOREGROUND_BLUE );
cout<<"will ";
SetConsoleTextAttribute ( h, FOREGROUND_INTENSITY | FOREGROUND_RED );
cout<<"be ";
SetConsoleTextAttribute ( h, FOREGROUND_INTENSITY | FOREGROUND_GREEN );
cout<<"in ";
SetConsoleTextAttribute ( h, FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_RED );
cout<<"technicolor ";
SetConsoleTextAttribute ( h, FOREGROUND_BLUE | FOREGROUND_GREEN );
cout<<"rainbow :D"<<endl;
SetConsoleTextAttribute(h, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED);
return EXIT_SUCCESS;
}
Hey Prelude any recommendations on my coding style? Please......
The conio.h doesn't work because all it has are function prototypes, structs, enums, ect. But, it does not have actual function implementations. Those are found elsewhere and are linked to the .h normally(at least thats what i think).
As I said before anything blame it on Denethor2000 LMAO lol....
:D
Code:#ifndef _CONIO_C_
#define _CONIO_C_
/* Please keep all functions alphabetical! */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <windows.h>
#include "conio.h"
int __FOREGROUND = LIGHTGRAY;
int __BACKGROUND = BLACK;
void _setcursortype(int _type) {
CONSOLE_CURSOR_INFO Info;
Info.bVisible = TRUE;
if (_type == _NOCURSOR)
Info.bVisible = FALSE;
else if (_type == _SOLIDCURSOR)
Info.dwSize = 100;
else if (_type == _NORMALCURSOR)
Info.dwSize = 1;
SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE), &Info);
}
void clreol() {
/* What does this function do? */
}
void clrscr() {
COORD coord;
DWORD written;
CONSOLE_SCREEN_BUFFER_INFO info;
coord.X = 0;
coord.Y = 0;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);
FillConsoleOutputCharacter (GetStdHandle(STD_OUTPUT_HANDLE), ' ',
info.dwSize.X * info.dwSize.Y, coord, &written);
gotoxy (1, 1);
}
int cputs(const char *_str) {
printf ("%s\n", _str);
return 0;
}
int getche() {
int ch;
ch = getch ();
printf ("%c\n", ch);
return ch;
}
void gettextinfo(struct text_info *_r) {
CONSOLE_SCREEN_BUFFER_INFO Info;
GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), &Info);
_r->winleft = Info.srWindow.Left;
_r->winright = Info.srWindow.Right;
_r->wintop = Info.srWindow.Top;
_r->winbottom = Info.srWindow.Bottom;
_r->attribute = Info.wAttributes;
_r->normattr = LIGHTGRAY | BLACK;
/* _r->currmode = ; */ /* What is currmode? */
_r->screenheight = Info.dwSize.Y;
_r->screenwidth = Info.dwSize.X;
_r->curx = wherex ();
_r->cury = wherey ();
}
void gotoxy(int x, int y) {
COORD c;
c.X = x - 1;
c.Y = y - 1;
SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), c);
}
void gppconio_init() {
/* Do nothing */
}
void highvideo() {
if (__FOREGROUND <= BROWN)
textcolor (__FOREGROUND + 9);
if (__BACKGROUND <= BROWN)
textbackground (__BACKGROUND + 9);
}
void insline() {
printf ("\n");
}
int putch(int _c) {
printf ("%c", _c);
return _c;
}
void textattr(int _attr) {
SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), _attr);
// printf ("%d\n", text_info.screenheight);
}
void textbackground(int _color) {
if (_color == BLINK)
_color = WHITE;
__BACKGROUND = _color;
textattr (__FOREGROUND | (_color + 29));
}
void textcolor(int _color) {
if (_color == BLINK)
_color = WHITE;
__FOREGROUND = _color;
textattr(_color | __BACKGROUND);
}
int wherex() {
CONSOLE_SCREEN_BUFFER_INFO info;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);
return info.dwCursorPosition.X;
}
int wherey() {
CONSOLE_SCREEN_BUFFER_INFO info;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);
return info.dwCursorPosition.Y - 2;
}
void window(int _left, int _top, int _right, int _bottom) {
SMALL_RECT R;
R.Left = _left;
R.Top = _top;
R.Right = _right;
R.Bottom = _bottom;
SetConsoleWindowInfo (GetStdHandle(STD_OUTPUT_HANDLE), TRUE, &R);
gotoxy (_left, _top);
}
#endif _CONIO_C_
does the namespace part have to be there for it to work? because it says std isnt a real namespace
>Hey Prelude any recommendations on my coding style?
Start taking advantage of loops so that you can make the program shorter. There are two extremes, one is too compact and the other is way too much code for something simple. What you need to do is find a happy medium that is easy to read but not exhausting.
-Prelude
Thanks.....
Maybe you can help me with this -
typing(char* Text, int speed){
HANDLE h;
h = GetStdHandle ( STD_OUTPUT_HANDLE );
for (int i = 0;Text[i] != '\0';i++)
{
Text[i - 1] = SetConsoleTextAttribute(h, FOREGROUND_INTENSITY);
cout << Text[i]<< flush;
Sleep(speed);
}
return EXIT_SUCCESS;
}
this was supposed to type out char by char a sting, and as it goes along.. first type it in normal gray, then next letter would be normal gray, but the PREVIOUS would be darker gray. Like a shine running along the words as they come out. get it? could you plz help?
Sorry that looks like Win32 and I don't know it yet......I am planning to start learning it as soon as I finish this book though I am in chapter 19 out of 21.
-PreludeCode:#include <iostream>
#include <windows.h>
using namespace std;
#define WHITE FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE
int main ( void )
{
HANDLE h;
char Text[] = "This is a long stream of text with alternating colors";
int speed = 100;
h = GetStdHandle ( STD_OUTPUT_HANDLE );
for (int i = 0;Text[i] != '\0';i++) {
if ( i & 1 )
SetConsoleTextAttribute ( h, FOREGROUND_INTENSITY );
else
SetConsoleTextAttribute ( h, WHITE );
cout<<Text[i];
Sleep(speed);
}
SetConsoleTextAttribute ( h, WHITE );
cout<<endl;
return EXIT_SUCCESS;
}
ErGG! Thx for try, but i knew how to do that, with switch statements btw :) (feels proud)
but i want to know how to make it so like each new character becomes the head(which will be white) and then after a new character is added in front of it that one becones white, and the one that was previously the head goes back to normal colors, so like the ONLY white letter is the newest character, which will then be grey when another letter pops in front of it. kinda like a worm with a white head and a gray body. get it?
ty in advance ^_^
Piece of cake, but you will have to make use of the gotoxy function that is defined in the Cprogramming FAQ.
-PreludeCode:#include <iostream>
#include <windows.h>
#include "myConio.h"
using namespace std;
#define WHITE FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY
int main ( void )
{
int y = 0;
HANDLE h;
char Text[] = "This is a long stream of text with alternating colors";
int speed = 50;
h = GetStdHandle ( STD_OUTPUT_HANDLE );
for (int i = 1;Text[i-1] != '\0';i++) {
SetConsoleTextAttribute ( h, WHITE );
cout<<Text[i-1];
gotoxy ( i-1, y );
Sleep(speed);
SetConsoleTextAttribute ( h, FOREGROUND_INTENSITY );
cout<<Text[i-1];
gotoxy ( i, y );
Sleep(speed);
}
SetConsoleTextAttribute ( h, WHITE );
cout<<endl;
return EXIT_SUCCESS;
}
erm,, r we 4getting sumthin? i dont have gotoxy !!!...
maybe you could post an alternate for it up here plz?
You might want to look a bit more closely then ;)
-PreludeQuote:
Piece of cake, but you will have to make use of the gotoxy function that is defined in the Cprogramming FAQ.
oh, sorry..looks like im 4getting sumthin.. brain maybe? hehe .. btw u wouldnt know the ascii for enter + space would yah?
why is this function hella crappin up my proggy?
when i try to run it, in the middle of the program it gives me an error about system.c
[code]
tinput(char* path, char color1, char color2,char color3)
{
HANDLE h;
h = GetStdHandle ( STD_OUTPUT_HANDLE );
int j = 1;
for (int i = 0;Text[i] != '\0';i++)
{
switch(j)
{
case 1:
SetConsoleTextAttribute (h, color1);
j = 2;
break;
case 2:
SetConsoleTextAttribute (h, color2);
j = 0;
break;
default:
SetConsoleTextAttribute (h, color3);
j = 1;
break;
}
cin>>path[i];
}
return *path;
}