Hey guys,
When I compile this code, it says it compiles successfully yet when I run with debugging, it says
1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
1>C:\Users\Chris\Documents\Cmpcsci101\Assignment12\Debug\Assignment12.exe : fatal error LNK1120: 1 unresolved externals
I cannot figure out what is wrong. My program is suposed to let the user input however many numbers, and then display the minimum and maximum number. Can somebody please help me ? My code is:
# include <iostream>
using namespace std;
double num, maxv, minv, count, sum;
char answer;
int N;
int main()
{
for (count=1; count<N; count++)
{
sum = 0;
cout<<"Please enter the number." <<endl;
cin>>num;
if (num < minv)
minv = num;
if (num > maxv)
maxv = num;
cout<<"Do you want to enter another number (y/n)? "<<endl;
cin>>answer;
}
while (answer == 'y' || answer == 'Y');
cout<<"You entered" <<N<< " numbers. "<<endl;
cout<<"The maximum number was " <<maxv<< "and the minimum number was " <<minv<< ".";
If N does not have a defined value, any behavior accessing it is undefined. The program doesn't know what you want N to be or when it "should" be a certain value. You'd be better off with a while. For loops are designed to run until a determinate number of iterations. Check the tutorial on this site if you don't know what a while is.
so what should I change to make it work? A do-while loop? How would I alter the count=1, count<N, count++ to make it work for a do? Im too new to this to understand but I am getting really frustrated and Just want it to work
A perfectly normal while loop would do. Your condition should be to check if the user inputted y or Y. Instead of incrementing a counter of inputted items in the loop statement, put it somewhere in the loop code section.
hi there highbies!!!! well any loop will acutally do it but i would suggest to use for-loop... for the algorith, try to swap the index of arrays.. and do it by making a while loop within a for loop... in the while loop you will try to make some conditions when to swap the index of arrays. jah get it???
for example:
9 8 7 6 3
if 9 > 8 then swap 9 to 8's place.
if 8 > 7 then swap 8 to 7's place. and so on... hope jah get it...
and to the highbies... have i done the right thing sir?
Uh, why would he use a for loop when the number of inputs is indeterminate? There's no point in keeping an array of the numbers. Only two numbers are necessary - the highest and the lowest. His current method of keeping track of them is more efficient and runs a tighter memory footprint than maintaining a list of all the numbers that have yet been inputted. In addition, since an array is not expandable an array would be a useless solution because, again, the input number is unknown. (Technically the solution to that would be to use a vector but that is unnecessary.) Although technically it could be done with either, while loops are better and certainly better style for an unknown number of iterations, as opposed to for loops whose syntax is designed to run a certain, determined number of times.
OIC sir... i havent used vector... as i see from his source code we are on the same level of learning c++ we havent taught yet of such vectors... as for us we determine it by using vectors
If you replace the for line with "do", your looping will work. Next, sum is initialized to zero inside of the loop; it should be initialized before the loop and num should be added to it each iteration. Lastly, initialize another variable to zero before the loop and increment it inside the loop each iteration to get the total count. Note that you'll also want to initialize maxv and minv.
I'm new to C++ and wanted some more practice writing code. Here is my two-cents with regards to writing your program. I'm not sure if it's the absolute best way to write it, but it works.
#include <iostream>
usingnamespace std;
int main(){
double max, min, val, avg = 0;
int counter = 0;
char cont;
cout << "This program lets you enter values until your fingers bleed!";
do {
cout << "\n\nPlease enter a number: ";
cin >> val;
counter++;
cout << "\n";
if(counter == 1){ //initialise values of min and max on first run through, but not on subsequent runs
min = val;
max = val;
}
if(val < min) min = val;
if(val > max) max = val;
avg += val;
cout << "Do you wish to continue(y/n)?";
cin >> cont;
} while(cont == 'y' || cont == 'Y');
cout << "\nYou entered " << counter << " numbers.\n\n";
cout << "The highest was " << max << " and the lowest was " << min << "\n\n";
cout << "The average of the numbers is " << avg / counter << "\n\n";
}
my bad. Do you think you can help me with a problem i posted the other day? No replies thus far - it's still on the first page of 'beginners' and has the title 'if criteria problem in recursive function'. Thanks.