Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

after line 86 you need to actually read a line from the file -- you can't just simply ignore it.

string line;
for(i = 0; i < 6; ++i)
{
    getline(infile,line);
    if( i > 1)
    {
          // convert to number, you can use stringstream class to do that.
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 13 -- you forgot the semicolon at the end.

line 15: need to escape the '\' character djout.open("C:\\TEST.txt"); I'm not going to tell you the rest of the errors. Just fix them one at a time and compile after each correction.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what do you think the answer is? If you have 30 apples and I give you 20 more then how many apples will you have? The answer is that simple.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>what are code tags i dont understand why i got an infraction
Look very closely in that edit box -- there are grey words there that explain code tags. Also read the rules because they are explained there too. Finally read the Announcements at the top of the c++ board because this is the third place where they are explained. You got two infractions so far because you have failed to read any of the above mentioned threads.

>>what do you mean by check the amount in the loop
It means to verify that the loops do not exceed the number of entries you made. loadScores() (should) change the value of amount to be the number of integers you enter at the keyboard. Just use that value in other places, something like below which was extracted from function displayArray()

while( x[i] >= compe[j] && i < size && j < size)
   {
      cout<< x[i] << "  ";
      i++;
      Gfrequency[j]++;
   }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

What? there is nothing to correct because the function even already returns true or false, unless you just want to rewrite it like this:

bool even(int x1)

{

return (x1%2 == 0) ? true : false;

}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>im using I/O with this data set
doesn't matter -- the program should work the same with any data set.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

And if you initialize array x on line 17 to 0 you will not get all those crazy numbers. int x[100] = {0};

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

This is the output I get. It is obvious you are failing to check for maximum quantity of numbers entered at the keyboard.

10
20
50
60
^Z
Grade Distribution
==================
A:
B:
C:
60 50 20 10 D:
-858993460 -858993460 -858993460 -858993460 -858993460 -858993460 -8589934
60 -858993460 -858993460 -858993460 -858993460 -858993460 -858993460 -858
993460 -858993460 -858993460 -858993460 -858993460 -858993460 -858993460
-858993460 -858993460 -858993460 -858993460 -858993460 -858993460 -8589934
60 -858993460 -858993460 -858993460 -858993460 -858993460 -858993460 -858
993460 -858993460 -858993460 -858993460 -858993460 -858993460 -858993460
-858993460 -858993460 -858993460 -858993460 -858993460 -858993460 -8589934
60 -858993460 -858993460 -858993460 -858993460 -858993460 -858993460 -858
993460 -858993460 -858993460 -858993460 -858993460 -858993460 -858993460
-858993460 -858993460 -858993460 -858993460 -858993460 -858993460 -8589934
60 -858993460 -858993460 -858993460 -858993460 -858993460 -858993460 -858
993460 -858993460 -858993460 -858993460 -858993460 -858993460 -858993460
-858993460 -858993460 -858993460 -858993460 -858993460 -858993460 -8589934
60 -858993460 -858993460 -858993460 -858993460 -858993460 -858993460 -858
993460 -858993460 -858993460 -858993460 1245080 4272406 1 9256408 924983
2 -633697869 0 0 2147336192 3579545 0 0 1245184 0 1245020 142 124514
8 4264096 -630588893 0 1245088 4271965 1245100 1980315699 2147336192 12
45164 2002954685 2147336192 1232591 0 0 2147336192 0 0 0 1245112 0 -
1 2002750450 2003025963 0 0 0 4264346 2147336192 0 2020893505 32 1 1
2296 220 0 32 0 20 1 7 52 364 1 0 0 0 0 0 2 438759246 644 68
716 608 0 760826203 1324 50 1376 768 0 -214797894 2144 74 2220 798
0 852421325 3020 66 3088 822 0 944791496 3912 94 4008 872 0 F:
==================
Grade Frequency
===============
A: 0
B: 0
C: 4
D: 193
F: 0
===============
n = 5
Class Average: -1.71799e+008
Class STD: 3.43597e+008
Press any key to continue . . .

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It isn't working because you changed that function wrong. It was correct the first time. After that you need to add checks that loops don't check beyone the value of amount because that is how many valid items are in the array.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The infinite loop is the one that starts on line 68 because the i is never incremented.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>the program gives me an infinite loop
where ? If you don't know where then add some print statements or use your compiler's debugger.

And your bubble sort algorithm is wrong because it goes through too may iterations and comparisons.

void sortScores( int x[], int size )
{
   for( int i = 0; i < size - 1; i++ )
   {
      for ( int j = i+1; j < size; j++ )
      {
         int temp;
         if ( x[ i ] < x[ j ] )
         {
            temp = x[ i ];
            x[ i ] = x[ j ];
            x[ j ] = temp;
         }
      }
   }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>How would I go about completing this task?
Did you try to compile the program? If you did, what errors did the compiler produce? If you did not compile it, why not? Hint: lines 7, 13 and 14 are wrong.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Assuming you are writing a C console program then use the system() function. MS-DOS has been dead on PCs for 10+ years now, but still used in some old embedded systems.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Are you talking something along the lines like this, to eliminate all the numbesr divisible by two
I don't know -- all I know is what you posted.

>>how would i print the subscript of the array if it is set to 1?
Simple -- create another loop that looks at all the elements of the array, not just every other one, check if its value is 1, and if it is then print the value of the loop counter.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Your description of the problem doesn't make sense. First you say to initialize all elements of the array to 1. That's simple enough to do.

for (int i = 0; i < arraySize; i++)
    a[i] = 1;

>>Starting with array subscript 2, every time an array element is found whose value is 1
Well since we set all elements to 1 as above then the 2nd subscript will be 1. So your program should set elements 2, 4, 6, 8, 10, ... 5000 to the value of 0 and leave all others alone.

for (int i = 2; i < arraySize; i += 2)
    a[i] = 0;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Turbo C Ver 1 also prints, so it's probably a bug at least through ver 3. Borland 5.5 works as expected.

As reported earlier I used TC Version 2.01 and it did not have that problem.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>it isn't the best thing to mix io functions from different families
but scanf() and fgets() are of the same family of functions, all declared in stdio.h But it is NOT good to use scanf() for string input because it can (potentially) corrupt and possibly crash your program if you enter a string that is longer then the buffer size you want to hold it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

teach me how to format my program befor posting

Its really simple, just put [code=c] at the top and [/code] at the bottom.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I just tried it with VC++ 2005 Express and TC (the original I think, dated 1989). Neither compiler had the problem you report.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I suppose you think we are that stupid? That isn't your program because it does not do anything that is required in your assignment that you originally posted. We aren't as dumb as you might think we are.

Trash that entire program and begin a new one. This time we want to see YOUR work, not someone elses.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
void foo()
{
   // ask for input
   // if input != 0 do recursion
   // print the number entered in this instance of the function and print a comma after it
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

That's not hard to do, but you have to be very careful of getting stack overflow errors. And that's pretty each to do with recursive functions.

>>I'm stumped again
Do you know what a recursive function is? If not then read about them in your text book. Its simply a function that calls itself.

int foo()
{
   foo(); // recursion
}

Don't compile or run the above because it will kill your os.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Of course, you cannot do this with columns. That's a problem for another day
Sure you can -- if what you mean is you can not sort by columns rather than by rows. Its possible to sort all rows by a specific column or all columns by a specific row. Might not make much sense to do it, but it is possible.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you need to change the sort function to sort one column of a two-dimensional array

void sortarrray(int t[][10], int NumRows, int ColToSort)
{
   // sort code here
}

>>it also asks me to do a binary search...would it change if its a 2d array?
Very similar to the way you would sort it. Start out using the normal binary search algorithm for a one-dimensional array then expand it to use a 2-dimensional array that searches only one of the columns.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The problem is that you are recursively including A.hpp and B.hpp. So solve the problem, just pre-declare the classes

#ifndef B_HPP_
#define B_HPP_
class A; 
#include "A.hpp" 
class B
{
public:	
      B();	
      virtual ~B();
 private:	
      A* apt;
};
#endif /*B_HPP_*/
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

how do I create a calender program using c++?

If you were "smarter than a 5th grader" then you could just simply "copy" from the previous poster. But be aware that if he is also wrong you will have to post "I Antwane am NOT smarter than a 5th grader." and flunk out of school.

[edit]For those not in USA "Are You Smarter Than A 5th Grader" is a popular current TV game show where the contestent can win up to $1,000,000.00 for answering ten 1st through 5th grade questions.[/edit]

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster


@ Ancient Dragon

Come at my home India and enjoy the Indian food. :)

Might be easier to just email or PM it to me :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

good point -- done.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Is there a way to change the title of the thread so that it more accurately reflects the contents?

Yes, but why now that it's been marked solved ?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Yes, I agree that is a much better solution. With vector or list there is no need for stdarg.h or for writing an infinite amount of templates.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Now if someone would just delete those obnoxious posts!

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>is that correct?
yes

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

> There are no compilers that support it
the output that i posted is with the code compiled by gcc 4.3 today; they are not my visualization of how it would look like in 2020.

You are fortunate -- I tried it with VC++ 2005 Express and Dev-D++ Version 4.9.9.2 and they both puked out lots of errors.

> we still have to resort to stdarg.h to get variable argument functions you may have to. i do not. even without gcc 4.3.

Apparently I'm not alone! I suspect you think everyone should abandon their compilers and get gcc 4.3 (note: I'm not trying to insult you here, just poking a little fun) :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 27: what is that length function you are calling? In your program number is the length of the array so there is no need to call another function just to get that. You don't need total_facts at all, just replace it with number on line 28.

There really is no need for that array at all. Just use the loop counter on line 29 because it contains the same values as that array.

This is all you need

int n = 1;
    for(int i = 1; i <= number; i++)
    {
       n *= i;
    }
joshua.tilson commented: Thank you for the help! +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>
but there is good news. c++ programmers will never have to use the unsafe and error-prone <cstdarg> ; c++0x has a solution. using variadic templates, we can write a typesafe function taking an arbitrary number of arguments of arbitrary types. http://en.wikipedia.org/wiki/C++0x#Variadic_templates

here is how you would write largest_of a variable number of values in c++0x.

#include <iostream>
#include <string>
// compile with gcc 4.3 with the -std=c++0x switch

template< typename T > inline 
const T& largest_of( const T& a, const T& b )
{ return a>b ? a : b ; }

template< typename T, typename ...REST > inline
const T& largest_of( const T& first, const REST&... rest... )
{ return largest_of( first, largest_of( rest... ) ) ; }

int main()
{
  std::cout << largest_of( 1, 9, 2, 8, 3, 7, 4, 6, 5 ) << '\n' ;
  std::cout << largest_of( 5.3, 8.9, -3.2, 17.8, 4.2, 7.0 ) 
          << '\n' ;
  const std::string s1("abc"), s2("2345"), 
                 s3("vufuk"), s4("ffyfyu") ;
  std::cout << largest_of( s1, s2, s3, s4 ) << '\n' ;
}
/**
>g++43 -Wall -std=c++0x -pedantic -Werror largest_of.cc && ./a.out
9
17.8
vufuk
*/

Greate news for the graduating Class of 2020. There are no compilers that support it since the standards have not been approved yet so we still have to resort to stdarg.h to get variable argument functions.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

My favorite is Chinese combo fried rice. My least is Greek and I've never eaten anything specifically from India or Ireland (I don't think so anyway).

I see someone voted USA -- the only things I can think of that are specifically American are pot stew and maybe McDonalds. Although very popular here pizza was invented in Italy and popularized in Naples.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

> just how would that help the OP create a function that takes a variable number of arguments
you can call max with anything between 2 to 8 arguments; that is a variable number in my book. .

But a very poor implementation because you had to create a template for each number of arguments -- 8 arguments = 8 templates. What if he wants 50 arguments, do you want to write 50 templates ? that's why varargs.h is a better solution -- not perfect as Salem pointed out, but workable. One function -- an infinite (almost) number of arguments, and you don't have to screw around writing millions of templates or overloaded functions.

As for boost libraries -- I don't know, but it might have a better solution.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

> I want to make a program with a max function taking any number of type double and returns the greatest of them

for a small number of arguments (upto about seven or so), you could use overloaded function names.

And just how would that help the OP create a function that takes a variable number of arguments ? At least two problems with the templates you posted: (1) none of them take a variable number of arguments, and (2) the arguments are all the same data type, which is not necessarily the case with functions that take a variable number of arguments.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you are missing this because the constructor at line 8 was never coded.

template<class T>
Pair<T>::Pair( )
{ }
Duki commented: solved my problem. +4
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

see this thread that was posted only a couple hours ago.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

zandiago: lines 11 and 12 are reversed -- you have to do the mod before the division.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

remove the semicolon at the end of the for loop statement!

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>modulo arithmetic
Not much to it -- modulo is the result after division. For example 15/10 = remainder 5. So 15 % 10 = 5. 27 % 10 = 7. After that just do normal division by 10 to remove the last digit from the number.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Aside from your atrocious spelling, and absolute terrible writing ability

I doubt English is his native language. You try writing in a language you don't know very well and you too will have that exact same problem. DaniWeb does not require people to be English majors or native English speakers. I've seen people born and raised here in St Louis MO that can't spell either.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>AD - no disrespect, but I don't want you programming for my bank!
Shucks! And I was going to funnel those extra pennies into my own bank account :)

But your solution has the same problem as mine -- upgrading from float to double does not affect that possible imprecision.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Did your instructor give you some requiements what TMoney is supposed to look like? Or are you free to write it any way you want ? Personally I think your class contains way too many methods to do only the few things you posted, and the only data object you need is float money; . Given that, Print() can be reduced to this because cout will display the negative sign if needed and the decimal point.

void TMoney::Print(){
    cout << precision(2) << width(4) <<  money << "\n";
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

After looking at that a little more I see you don't need to use any loops at all -- the program can be written without loops. I assume the output should look like this: Using loops like you did causes too many conversions.

This is a conversion program for U.S. dollars into euros,yens, and rupees or vice versa
Please enter the three-letter symbol of the original currency:
USD for Dollars
JPY for Yen
EUR for Euros
INR for Rupees
jpy

Please enter the amount to be converted: 1
109.427 USD
158.907 Euro
2.78235 Rupees
Press any key to continue . . .

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

1. After entering symbol1 you could transform the string to all upper case characters so that the rest of the if statements do not need to check for lower case or any other case mixture. transform(symbol1.begin(),symbol1.end(),symbol1.begin(),toupper); You need to include <algorithm> to compile the above line

2. The problem you report caused by all those row loops. If I were you I'd create four different functions that perform the conversion for each currency, then they can be easily and efficiently called as required after line 49. For example

if( symbol1 == "USD")
{
    ConvertJPY(amount);
    ConvertEUR(amount);
    ConvertINR(amount);
}
else if( symbol1 == "JPY")
{
    ConvertUSD(amount);
    ConvertEUR(amount);
    ConvertINR(amount);
}
else if( symbol1 == "EUR")
{
    ConvertUSD(amount);
    ConvertJPR(amount);
    ConvertINR(amount);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 11: that works only at the time the line is executed. If you add new items to the front then you have to call begin() again in order to get pointer to the new front.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It means to wrap your code in [code] and [/code] tags so they are easily readable. For example:

Thanks for posting that -- I've been wondering how you posted that without using spaces between the brackets. Didn't know about the noparse tags.:)