mrnutty 761 Senior Poster

sorry i forgot to post my code

#include <stdio.h>

int main() {

int i ;
int c;

while ( ( i = getchar() ) != EOF )
c++ ;

printf( "%d characters\n" , c) ;

return 0;
}

does this seem ok? ... when i run it ./a.out i click enter
then i enter a word say "daniweb" and press enter and then hit ctrl+d and it says 8 characters

where is c initialized ?

tux4life commented: Tada! The actual thread solver. +24
mrnutty 761 Senior Poster

Haven't used it for a while, but I think it takes the ascii value in int form.

if you wan't to use variable use a char variable

char print ='0';
for(print = '0'; print != '9'; print++)
  glutStrokeCharacter(GLUT_STROKE_MONO_ROMAN, print);

Also google the function, and you get a documentation, like this

mrnutty 761 Senior Poster

Yes, use template.

You could use template specialization, to make sure that the template
parameters is a number.

Here is a way to do that :

#include <iostream>

using namespace std;


template<typename Type>
struct is_numeric { static const int i = 0; };

//Template specilization
template<> struct is_numeric<short>				{ static const int i = 1; };
template<> struct is_numeric<unsigned short>	{ static const int i = 1; };
template<> struct is_numeric<int>				{ static const int i = 1; };
template<> struct is_numeric<unsigned int>		{ static const int i = 1; };
template<> struct is_numeric<long>				{ static const int i = 1; };
template<> struct is_numeric<unsigned long>		{ static const int i = 1; };
template<> struct is_numeric<float>				{ static const int i = 1; };
template<> struct is_numeric<double>			{ static const int i = 1; };
template<> struct is_numeric<long double>		{ static const int i = 1; };

template<typename Type>
class Numeric
{	
	//Check is Type is numeric
	int AssertType[is_numeric<Type>::i];

	Type * Vector_;
	unsigned int length;
public:
	Numeric()	{ Vector_ = new Type[0]; };
	~Numeric()  { delete [] Vector_; }
};

int main()
{ 
	Numeric<int> a;
	Numeric<float> b;
	Numeric<unsigned short> c;
	Numeric<string> d; //Error  
	Numeric<char> e; //Error  
	

	return 0;

}
StuXYZ commented: Nice, easy to understand template traits example +6
mrnutty 761 Senior Poster

but I have looked at this tutorial and it uses glut to make the window and print to it, how come?

Well it can do some printing stuff too, but its primary task is to create
the window and get inputs. You should use opengl to draw stuff. Of
course there are some draw stuff that makes your life easier, which
glut has, like drawing text or a sphere, among other things.

MattyRobot commented: he helps me time and time again +1
mrnutty 761 Senior Poster

portability :

"The actual type of size_t is platform-dependent; a common mistake is
to assume size_t is the same as unsigned int, which can lead to
programming errors, particularly as 64-bit architectures become more
prevalent"

KonkaNok commented: ..just what I was looking for. +1
mrnutty 761 Senior Poster

goggle Separating axis theorem.

jasimp commented: Love your avatar pic. Nice suggestion too :) +11
mrnutty 761 Senior Poster

The errors that I have are:

error C2228: left of '.print' must have class/struct/union

This is from this code :

//prompt customer for savings balance and print the balance out
	savingsAccount.calculateMonthylyInterest().print();

To solve it you can do 2 things :
1) Make calculate return the object
2) or use the call separately like so :

savingsAccount.calculateMonthylyInterest();
savingsAccount.print();

error C2511: 'void Savings_Account::modifyInterestRate(double)' : overloaded member function not found in 'Savings_Account'

That error is related to this.

static double modifyInterestRate(); //prototype
//and its definition 
void Savings_Account::modifyInterestRate(double aI)
{
	if(aI > 0 && aI <1)
	{
		annuallyInterestRate = aI;
	}
	else 
		annuallyInterestRate =0.03;
}

Do you see the difference? Change the prototype to
match its definition. So it should be

void modifyInterestRate(double);
//instead of 
//static double modifyInterestRate();

error C2065: 'aI' : undeclared identifier

This is from this snippet :

double Savings_Account::calculateMonthylyInterest()
{
	double customerSavingsBal;
 
	cout << "Please enter your savings balance: ";
	cin >> savingsBalance;
 
	customerSavingsBal= savingsBalance * aI; //<-- HERE
}

Where is aI declared in there? Did you mean to pass it as a parameter?
If so then you need to change the functions prototype as well.

error C2662: 'Savings_Account::calculateMonthylyInterest' : cannot convert 'this' pointer from 'const Savings_Account' to 'Savings_Account &'

That is probably from the other errors.

1 more this , this code is meaningless,

double Savings_Account::calculateMonthylyInterest()
{
	double customerSavingsBal;
 
	cout << "Please enter your savings balance: ";
	cin >> savingsBalance;
 
	customerSavingsBal= savingsBalance * aI;
}

customerSavingBal goes …

mrnutty 761 Senior Poster

Ask the Google god. Type your question into Google and all your questions
shall be answered.


Note: Not reliable for everything.

majestic0110 commented: lol :) +5
mrnutty 761 Senior Poster

come on. i want find the answer

The answer is within you my child. Just unleash it!

Salem commented: Ah yes grasshopper, to know the path is to know the way +36
tux4life commented: Indeed! +21
mrnutty 761 Senior Poster

When accessing elements of array, the index number must
be a integral type.

so

int Array[4];
Array[4] = 1;//valid
Array[2] = 9;//valid
Array[-3] = 3; //valid but a bug
Array[3.14] = 3; //Wrong

Your code :

pur[nWeek][counter] = purchase;

Booth nWeek and counter is of type float. So either change
the parameters or typecast like so :

pur[ int (nWeek) ][ int (counter) ] = purchase;

The above is dangerous and could be buggy

Salem commented: Got there first +36
mrnutty 761 Senior Poster

How well do you know c++?

for loops, do while, if else, class, ...?

Also there is practice problem here.

tux4life commented: Indeed :) +19
mrnutty 761 Senior Poster

>Whats up with the attitude?
Remove: the h*ll from that sentence :P

Then it would be grammatically incorrect.

Nick Evan commented: Hehe. +25
mrnutty 761 Senior Poster


Yet another way (albeit more long winded, but still correct!):

const int student, subject;
student=5;
subject=3;
int marks[student][subject];

So all three of the above snippets of code do exactly the same thing. But the first two are shorter and more succinct!

I don't know about your compiler, but mines dosen't allow
declaration of of const object without being initialized. So the
above code would be an error.

Just for the sake of it, take a look at the errors, and see why
one wrong thing can lead to many errors.

error C2734: 'student' : const object must be initialized if not extern
error C2734: 'subject' : const object must be initialized if not extern
error C3892: 'student' : you cannot assign to a variable that is const
error C3892: 'subject' : you cannot assign to a variable that is const
error C2057: expected constant expression
error C2466:cannot allocate an array of constant size 0
error C2466: cannot allocate an array of constant size 0
error C2087: 'marks' : missing subscript
error C2133: 'marks' : unknown size
JasonHippy commented: Good spot, consider myself rightly corrected! +2
mrnutty 761 Senior Poster

which line does it point to?

mrnutty 761 Senior Poster

Try creating your own

Salem commented: Such an elegant and obvious answer :) +36
mrnutty 761 Senior Poster

#include "Employee Class.cpp"

There should be no space between the name , it should be

#include "EmployeeClass.cpp"

mandofl commented: Gives good advice +1
mrnutty 761 Senior Poster

Create an array;
From 'i' to 'SIZE' store 'i' into array.
shuffle array;

extract info from array into new one, without the same index
repeating.

DangerDev commented: nice solution +2
mrnutty 761 Senior Poster

No!!!


These are the exact same thing. If the block of code to be executed is only one line, no brackets are needed, though they don't hurt.

True. The compiler doesn't care of which way you use it,however, since
you are starting, you should use brackets so you can save mistakes from happening.

Salem commented: A consistent approach over option syntax will definitely save trouble at some point - good +36
mrnutty 761 Senior Poster

" YOU (firstPerson): Hi! I'm the sucker who's gonna help you cheat your
class! Here's the code including comments! Say hi to your teacher for
me ok? "

Hilarious. Ok, no more freebies. I thought he was trying to learn
opengl. Didn't think that its a HW question. By the way is it Sunyah?

Nick Evan commented: Lesson learned :) +24