hi all after talking with yonghc i have a working version. i am going to be doing some performance testing to see if i can make it better and will post it if i come up with anything.
NathanOliver 429 Veteran Poster Featured Poster
hi all after talking with yonghc i have a working version. i am going to be doing some performance testing to see if i can make it better and will post it if i come up with anything.
sorry i used the wrong word. i use Microsoft visual studio professional 2005 and you can write win 32 console apps without using stdafx.h all you have to tell it is to make an empty project and not to use the precompiled headers. its more of a matter that i want total control and not that there is anything wrong with what they give you to start with.
i use windows and when you create a new win 32 app all you have to do is tell it not to precomplie the headers and use an empty project. this way you get and empty project and can do whatever you want. i never use stdafx.h unless i need it.
well i got it running. i deleted the #include "stdafx.h"
and changed qu_main(argc, argv)
to int main()
could you supply me with the maze info so i can run it on my machine and see what its doing?
thanks much firstPerson.
in your if statements in your maze traverse function you have (x+1, y) != 'A'
. im not quite sure what this is. did you mean to do if (mouse[x+1][y] != 'A')
also on line 38 you have if (maze[x][y] == 'T')
but there is no maze variable declared in either the mazemania class or in the traverse function.
you need to use the single quotes for testing charectures. 'y'
whet testing single chars you need to use the single quote such as
if (op == '+') // this is okay
if (op == +) // this is not okay
also when you are testing conditions you are using a single =. testing equality in c++ is done using ==
if (foo == boo) // testing if foo equals boo
if (foo = boo) // makes foo equal to boo
Hi all. I am currently writing a large number class and was curious if I should use a template. I am setting up my constructors and I have one for a string and i was thinking i could use a template for a constructor so it can take in an int, float, double, etc. instead of writing a constructor for each type.
template<typename T>
Number
{
Number();
Number(string);
Number(T); // cover for built in number data types
}
I'm thinking this will make writing the code easier but I'm not sure if this will have unexpected consequences down the line. besides the fact some one could try and put a dog into the Number.
yeah that is true tux. i normally use getline but this was a really quick and dirty example. i would hope the O.P. would use good programing techniques in his code.
i would avoid using system("pause") in your programs. if you search this site you will find some nice examples why not to.
also line 30 should be size = arraysize
not the other way around.
no problem
that is the problem
cout << 'a'; // good
cout << ' '; // good
cout << 'ab'; // bad
cout << ' '; // bad
on lines 3-6 you are checking if the accnum==accountnum and if it doesnt return -1. so one the frist time if the number isnt equal then it will return -1. i would suggest re writting the loop as
for (int i = 0; i < 1000; i++)
{
if (accnum == accountnum[i])
return i;
}
return -1;
sorry one other mistake starting at line 5
int *counter = new int;
*counter = 0;
//...
this will fix the problem.
sorry i had a coding error line 18 should be (*counter)++
see if that fixes the problem
well if you are using just one array to store all the account numbers then
void create_account(int array[1000], int * counter);
int main()
{
int * counter = 0;
int accountnum[1000];
//.. do your menu
// when the user selects to create an account
creat_account(accountnum, counter);
}
void creat_account(int array[1000], int * counter)
{
int temp;
cout << "please enter an account number: ";
cin >> temp;
array[(*counter)] = temp;
*counter++;
}
this will keep track of how many number are in the array and every time you need to add a number to the it will put it in the right spot and update the number of numbers are in the array.
sorry. i was trying to explain this from memory but it was awhile ago that i read this.
http://www.parashift.com/c++-faq-lite/newbie.html
section 29.18 will explain what i did poorly. hope this clears it up a bit.
oh sorry well you can do that on the heap then like
//...
int a;
fin >> a;
string * S = new string[a];
//...
sorry didn't totally read your post. it sounds like you need to be writing a function for getting the account numbers in that case you could have the array and a variable that holds how many entries are in the array in your main function. then you could pass the array and the counter variable into the function and have it ask for the account number. then store the account number into the array at the counter + 1 and then increment the counter. in order to do this you will either have to pass the counter variable into the function by reference or as a pointer or have the function return counter + 1 and store that in counter. i hope i'm making sense with this.
you can have the input statement inside the loop
int accnum;
int accountnum[1000];
for (int i = 0; i < 100; i++)
{
cout << "please enter an account number: ";
cin >> accnum
accountnum[i] = accnum;
}
here is a simple brute force way of doing the nth root of a number.
#include <iostream>
using namespace std;
double NthRoot(double, int);
double RaisedTo(double, int);
double NthRoot(double number, int nthRoot )
{
bool done = false;
unsigned short int digits = 0;
double temp = number / 2;
double sqrt = 0;
double plusplus = 1;
if (number == 1)
return 1;
for (;;)
{
if (digits > 0)
plusplus /= 10.0;
if (digits == 12)
return sqrt;
for ( double i = sqrt; i <= (temp + 1); i += plusplus)
{
if (RaisedTo(i, nthRoot) > number)
{
sqrt = i - plusplus;
digits++;
break;
}
}
}
}
double RaisedTo(double base, int power)
{
double temp;
for (int i = 1; i < power; i++)
{
base *= temp;
}
return base;
}
int main()
{
double number = 0;
double answer;
int root;
cout << "Please enter a number to find the nth root: ";
cin >> number;
cout << "Please enter the root you wish to find: ";
cin >> root;
answer = NthRoot(number, root);
cout << "The " << root << "th root is: " << answer << endl;
cin.get();
cin.get();
return 0;
}
i haven't attempted to clock it but does return pretty quick with most numbers. also on line 20 is where you can set the precision you desire. i used 12 for a default
you really don't need to declare the size of the string when you create it. it is good practice to do so but the string will automatically re size itself when it needs to do so. this will make a little performance hit though.
the problem with the line of code you are using is that it is calling multiple functions. when the program runs it will take the return of the function and instead of keeping it in the registry it will put it into the ram which will truncate the number and then it will do the same with the other returns then read them all back and then give you your answer. one way you could solve this would be to make sure to do all the calculations first and then store them so you will have an equal truncation every time. hope this make sense.
i noticed on line 17 you a creating a new SYM object. have you tried using the new keyword?
SYM * temp = new SYM[N]; // using the size you passed into the function for the array
also you are starting the variable heads at one which will throw off you answer. you should initialize both heads and tails as 0.
a way you can do this would be to have a void check function inside a while loop in your main function.
void CheckInput(char[80], bool*);
int main()
{
char[80] cake;
bool good = false;
while (!good)
{
cout << "please enter a cake: "
cin >> cake;
CheckInput(cake, &good);
}
//...
}
void CkeckInput(char[80] cake, bool* good)
{
// run a switch checking cake agiants the valid choices
// if the check succeds then set good to true otherwies do nothing
}
im not sure if you are using pointers though so if you are not this solution wont work.
where are you setting the emp in the node. i see this block for file input
while (fin >> number)
{
head = new LISTNODE(emp , head);
}
but with this you are not doing anything. first you need pull the information into your employee struct and then add it to you list.
what exactly is you error?
wehat error arer you getting. also when you define a template you would normaly use the syntax
template <typename T, typename C>
class Template
{
//...
};
well if your complier is compiling project01.cpp be for your main.cpp file then it doesn't know what MAX_COLS is yet. try moving the declaration into the project01.cpp file and see what happens
well you could use the stl such as a vector or list or if your not allowed to do so you could copy the array into a new array skipping the one you want deleted and then delete the original array then return the new array.
also in the first program there is no memory leak.
you cant have an undefined amount of variables in function deceleration. you must declare what the function returns and all parameters the function takes. if you want to send a few or alot of one type of thing i would try using an array of some sort like
void foo(int[], size);
this way the person could send to the function however many ints or whatever you want to pass.
sorry but your post doesnt make sense. if we use 2/5 - 1/2 with your formula we get:
numerator = (2 * 2) - (1 * 5) = 4 - 5 = -1
denominator = (2 * 5) = 10
so your fraction should be -1/10. not sure why you are not getting it unless it has something to do with your simplify function
this code will solve only this problem and will do it in 36 iterations. just did it for giggles to see if i could. if you want a generic code then you will have to do other things ;)
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
string too = "", good = "";
char convert[5];
int temp;
for (int i = 1; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
if (j == i)
continue;
temp = (i * 100) + (j * 10) + j;
_itoa(temp, convert, 10);
too = convert;
_itoa((temp * 4), convert, 10);
good = convert;
if ((too[2] == good[1]) && (good[1] == good[2]) && (good[0] != good[3]) && (good[1] != good[3]) && (good.size() == 4))
{
cout << "SUCCESS!!!\n";
cout << "TOO = " << temp << "\n";
cout << "GOOD = " << (temp * 4) << "\n";
cin.get();
return 0;
}
cout << "too = " << temp << "\tgood = " << (temp * 4) << "\n";
}
}
cout << "sorry this didnt work.";
cin.get();
return 0;
}
could you please post your code
so your not sure how to get the abs_minimum? arent you calculating it in you next function
if (count <= 0)
{
count = 1;
total = r;
tinyest = r;
largest = r;
return;
}
count = count + 1;
total +=r;
if (r < tinyest)
{
tinyest = r; //<-- here you are setting the minimum.
}
if (largest < r)
{
largest = r;
}
}
all you have to do is return the absolute value of the minimum to satisfy the return value for the function. there are abs() functions in math.h that will do that for you or you could write your own
the size you want for the substring should be 13 not 14. that should help
yes it is. in order to do the comparison you need to tell the code what character to check. like:
for (int i = 0; i < somestring.length; i++
{
if (somestring[i] == '"')
{
//...
}
}
what string are you using? std::string or something else?
well if you want to check for a " in a string then you can write.
if (somestring[n] == ' " ') // i put a space between the single quotes and the double quote so you could see it. in your program just put '"'.
{
//...
i had a similar problem writing a string to a file and i got some good advice.
i think there is a win API function to see what programs are running but i cant remember. have you thought about multithreading instead?
well im not sure what is going on. i wrote a simple test program and ran it and it works fine for me. this is what i did.
#include <iostream>
#include <string>
using namespace std;
int main()
{
char * gen_arr[] = {
"Blues", "Classic Rock", "Country", "Dance", "Disco", "Funk", "Grunge",
"Hip-Hop", "Jazz", "Metal", "New Age", "Oldies", "Other", "Pop", "R&B",
"Rap", "Reggae", "Rock", "Techno", "Industrial", "Alternative", "Ska",
"Death Metal", "Pranks", "Soundtrack", "Euro-Techno", "Ambient",
"Trip-Hop", "Vocal", "Jazz+Funk", "Fusion", "Trance", "Classical",
"Instrumental", "Acid", "House", "Game", "Sound Clip", "Gospel",
"Noise", "AlternRock", "Bass", "Soul", "Punk", "Space", "Meditative",
"Instrumental Pop", "Instrumental Rock", "Ethnic", "Gothic",
"Darkwave", "Techno-Industrial", "Electronic", "Pop-Folk",
"Eurodance", "Dream", "Southern Rock", "Comedy", "Cult", "Gangsta"};
char country[30];
cout << "enter the word Coutnry: ";
cin.getline(country, 30);
if (_stricmp(country, gen_arr[2]) == 0)
cout << gen_arr[2];
cin.get();
return 0;
}
alright sorry total brain fart. char * gen_arr[];
is right. i did a simple test on my machine where i made a variable char * country = "Country";
and the used country and gen_arr[2] in the _stricmp funtion and it was fine. im wondering how you are getting the value of value. is it a char array or a string as in std::string
?
that definition doesn't work to make a 2d char array. if you want a 2d char array you could say char * gen_arr[2][7] = {"String1","String2"}