Thread: Errors When I Color

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User GreenCherry's Avatar
    Join Date
    Mar 2002
    Posts
    65

    Question Errors When I Color

    In this program I am trying to color the answers. If the answer is correct it is green and if incorrect it is colored red. But it wont color the individual letters. Il'l mark the area with the important stuff.

    Yes the code is long but i marked the part that needs to be looked at.

    FYI: There are no actual errors, it runs fine.

    If you hadnt noticed, the source file is under this post, so you can run it yourself. It will make more sence if you do.
    Code:
    #include <iostream.h>
    #include <iomanip.h>
    #include "apmatrix.h"
    #include "apvector.h"
    #include <stdlib.h.>
    #include <windows.h>
    
    //Easy Coloring Of Words/Letters
    #define Color_White SetConsoleTextAttribute(stdOut, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED);
    #define Color_Red	SetConsoleTextAttribute(stdOut, FOREGROUND_RED | FOREGROUND_INTENSITY);
    #define Color_Green SetConsoleTextAttribute(stdOut, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
    
    HANDLE stdOut = GetStdHandle(STD_OUTPUT_HANDLE);
    
    int main()
    {
    	Color_White
    	//Welcome
    	cout<<"***Welcome to Quiz Machine***"<<endl<<"*****************************"
    		<<endl<<"Please follow the directions"<<endl<<"to see the"
    		<<" results of your"<<endl<<"True/False test."<<endl<<endl;
    	
    	//Declaration of Varibles
    	apvector<int> student(2);
    	apmatrix<char> score(10, 3, 'F');
    	apvector<int> count(2);
    	apvector<char> grade(2);
    	int size, size2;
    	
    	//Gets amount of students
    	cout<<"How many students took the test? ";
    	cin>>size;
    	size2 = size +1;
    
    	//Resises vectors and matrix
    	student.resize(size);
    	score.resize(10, size2);
    	count.resize(size);
    	grade.resize(size);
    
    	for(int t=0; t<size; ++t)
    		count[t] = 0;
    	for(t=0; t<size; ++t)
    		grade[t] = '-';
    
    	//Insert answer key
    	cout<<"Enter the correct answers(10):"<<endl;
    		for(int x = 0; x<10; ++x)
    		{
    			cin>>score[x][0];
    			if(score[x][0] == 't')
    				score[x][0] = 'T';
    			if(score[x][0] == 'f')
    				score[x][0] = 'F';
    		}
    	
    	//Insert ID #'s
    	for(x=0; x<size; ++x)
    	{
    		cout<<"Please enter student "<<x+1<<"'s 4-digit ID number: ";
    		cin>>student[x];
    		while(student[x] > 9999 || student[x] < 1000)
    		{
    			cout<<"Please re-enter the student number: ";
    			cin>>student[x];
    		}
    	}
    	
    	//Insert Test Answers
    	for(x=1; x<size2; ++x)
    	{
    		cout<<"Please enter student "<<x<<"'s test scores(T/F):"<<endl;
    		for(int y=0; y<10; ++y)
    		{
    			cin>>score[y][x];
    			if(score[y][x] == 't')
    				score[y][x] = 'T';
    			if(score[y][x] == 'f')
    				score[y][x] = 'F';
    		}
    	}
    	
    	//Count correct Answers
    	for(x=1; x<size2; ++x)
    	{
    		for(int y=0; y<10; ++y)
    		{
    			if(score[y][0] == score[y][x])
    				++count[x-1];
    		}
    	}
    
    	//Sets Margin Left
    	cout<<setiosflags(ios::left);
    	
    	//Sets letter grades of all students
    	for(x=0; x<size; ++x)
    	{
    		if(count[x] == 10)
    			grade[x] = 'A';
    		else if(count[x] == 9)
    			grade[x] = 'B';
    		else if(count[x] == 8)
    			grade[x] = 'C';
    		else if(count[x] == 7)
    			grade[x] = 'C';
    		else if(count[x] == 6)
    			grade[x] = 'D';
    		else if(count[x] == 5)
    			grade[x] = 'D';
    		else
    			grade[x] = 'F';
    	}
    
    	system("cls");
    
    	//Print Key
    	cout<<setw(7)<<"Key";
    	for(int y=0; y<10; ++y)
    		cout<<score[y][0];
    
    ///////////////////////////////////////////////////////////////	HERE
    	//Prints results
    
    	for(x=0; x<size; ++x)
    	{
    		cout<<endl<<setw(7)<<student[x];
    		for(y=0; y<10; ++y)
    		{
    			if(score[y][0] != score[y][x])
    			{
    				Color_Red
    				cout<<score[y][x+1];
    			}
    			else if(score[y][0] == score[y][x])
    			{
    				Color_Green
    				cout<<score[y][x+1];
    			}
    			
    		}
    	//	Color_White
    		cout<<" # Correct: "<<setw(5)<<count[x]<<"Grade: "<<grade[x];
    	}
    	cout<<endl<<endl;
    
    ///////////////////////////////////////////////////////////////// TO HERE
    	//Class Average
    
    	double avg = 0;
    	for(x=0; x<size; ++x)
    	{
    		avg = avg + count[x];
    	}
    	avg = avg / size;
    	cout<<"Class Average: "<<avg<<" Correct"<<endl;
    
    	//Class Letter Average
    	char letter;
    	if(avg == 10)
    		letter = 'A';
    	else if(avg == 9)
    		letter = 'B';
    	else if(avg == 8)
    		letter= 'C';
    	else if(avg == 7)
    		letter = 'C';
    	else if(avg == 6)
    		letter = 'D';
    	else if(avg == 5)
    		letter = 'D';
    	else
    		letter = 'F';
    	cout<<"Letter Average: "<<letter<<endl<<endl;
    
    	return 0;
    }
    Last edited by GreenCherry; 10-24-2002 at 09:28 AM.
    I have a rabbit in my pants! Please be happy for me.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  2. Specific Character Text Color
    By TechWins in forum C++ Programming
    Replies: 5
    Last Post: 04-22-2002, 03:42 AM
  3. Text and background Color
    By Goof Program in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 03-29-2002, 06:59 PM
  4. errors in class(urgent )
    By ayesha in forum C++ Programming
    Replies: 1
    Last Post: 11-10-2001, 10:14 PM
  5. errors in class(urgent)
    By ayesha in forum C++ Programming
    Replies: 2
    Last Post: 11-10-2001, 06:51 PM