c++ problem: help!

problem:

write a program that should count and print the number of hot days (85 and above), pleasant days (60-84), and cold days (less than 60).
Show us what you have so far and we'll help you with anything specific that's holding you back.
I have created a form with 2 text boxes and, date picker and 7 listbox fields. I created a button and labelled it with SAVE. i would like to save all the info as a text document once I press the SAVE button but this doe not happen...please help
i've not yet arranged my codes, but im using -for- and -if- statements in this prog. can you help me arrange this codes??
Is there something holding you back from starting to write the code? Are you having trouble grasping some of the basics of C++? If so, give these tutorials a read:

http://www.cplusplus.com/doc/tutorial/program_structure/
http://www.cplusplus.com/doc/tutorial/variables/
http://www.cplusplus.com/doc/tutorial/constants/
http://www.cplusplus.com/doc/tutorial/operators/
http://www.cplusplus.com/doc/tutorial/control/

If you're still stuck, then by all means we can help with anything that needs clarification.

If you're not having trouble with the basics, then post what code you have and we'll see what we can do. We like to help here by providing gentle nudges as opposed to handing out solutions.

@Loganlucy07 You should create a new thread for your issue. However, with your problem formulated as is, people will ask for clarification. Please include some (nicely-formatted) code in your thread (and be sure to wrap code in code tags. This would be the <> button when editting your post).
here's my code sir...


int _tmain(int argc, _TCHAR* argv[])
{
int a,b,c,d;

printf("enter the number of entities(temperature) to be included: ");
scanf("%d",&a);
printf("enter temperature ranges:\n");
for (b=0;b<a;b++)
{
scanf("%d",&c);
}

im stuck here:
i don't know where to put these codes.. or what's next.. i really appreciate your help sir.. thanks!

if (c<60)
{printf("cold: %d",c);

if (c>85)
{printf("hot: %d",c);

if ((c>60)&&(c<85))
{printf("pleasant: %d",c);


getch();
return 0;
}
Is this for a C class or C++? If it's a C++ class, you should look into console input and output using <iostream>

My advice would be to do the following:

1. Initialize three counters to zero (one for the hot days, one for the pleasant days, and one for the cold days)
2. Ask the user for the amount of temperatures to be entered
3. For each temperature entered, increment one of the above counters based on the temperature
4. Display the results (these are stored in the counters)

Also, your current code doesn't cover the cases where the temperature is exactly 60 or exactly 85.
im currently using Microsoft visual studio 2010 and it can't read or find that file <iostream> so im using the stdafx.h

so the ranges must be <=60 for cold days, >=85 for hot days, and >60 but <85 for pleasant days..

so how am i gonna do that?

im currently using Microsoft visual studio 2010 and it can't read or find that file <iostream>

Really? #include <iostream> doesn't work? Please post the error(s) you're receiving. Did you start a console project? You might have to turn pre-compiled headers off. I find it easier to start an empty project and just start coding away because, otherwise, Visual Studio just adds a bunch of gunk.

so the ranges must be <=60 for cold days, >=85 for hot days, and >60 but <85 for pleasant days..

so how am i gonna do that?

In step 3 above, you would check the temperature using three if statements or an

1
2
3
4
5
6
7
8
9
if ()
{
} 
else if ()
{
}
else
{
}

construction. One if would check if the temperature inputted is <= 60, the other would check if the temperature is >= 85, and the other (or the else case) would check that the temperature is between 60 and 85. In each case, increment the appropriate counter.
im using the win32 console application..then i select the option "pre-compiled header..."

this is the problem im encountering.. for example i'll be running this codes:

#include <iostream>
using namespace std;

int main ()
{
int i;
cout << "Please enter an integer value: ";
cin >> i;
cout << "The value you entered is " << i;
cout << " and its double is " << i*2 << ".\n";
return 0;
}


a prompt will come out saying: "unable to start the program 'c:\users\bahay\documents\visual studio 2010\projects\wa\debug\wa.exe' the system cannot find the file specified."






the thing that i wanna know is how can i make the collected values of c be categorized in hot,cold, and pleasant days...can you show me the codes sir?
Last edited on
This thread may help you with your problem:
http://www.cplusplus.com/forum/beginner/4273/

Again, your problem may go away if you choose empty project instead of win32 console application. And, turn off pre-compiled headers if they're on.

the thing that i wanna know is how can i make the collected values of c be categorized in hot,cold, and pleasant days...can you show me the codes sir?

No, but I already gave you a detailed explanation. As I understand, for this assignment, you only need to keep track of the number of cold, hot, and pleasant days (you do not need to group them). The solution is to have three variables that are used to count each type of day. When the user enters a temperature, check what kind of day it is and increment the appropriate counter.
=) tnx for the help in my program!


now here's the error in my app.

1>c:\users\bahay\documents\visual studio 2010\Projects\waa\Debug\waa.exe : fatal error LNK1120: 1 unresolved externals

the other one in the thread that you gave is: 1>.\Debug\TheTest.obj : fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'x64'

so how's that? ive tried the solutions in that post but it didn't work



Last edited on
the other one in the thread that you gave is: 1>.\Debug\TheTest.obj : fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'x64'

so how's that?

A particular Visual Studio project can be built to multiple configurations. Say, for instance that you want to have a Debug build for testing and a Release build for deployment, you would simply build once under the Debug configuration and once under the Release configuration. Each .exe would be built to separate directories and you wouldn't have to change the code in the process. Visual Studio has these two configurations available for every project, though you can add your own configurations. You can make one configuration use a particular set of pre-processor directives, and you could have another which uses a different run-time library, for example.

A Visual Studio project can be built to multiple platforms. For instance, you can build the same project for use on an 'x86' processor (and give it to Win32 customers) and for use on an 'x64' processor (and give it to Windows customers with a 64 bit OS). Depending on your machine and Visual Studio installation, you can build for other platforms such as an Itanium processor.

You can see the current configuration and platform at the top of the main GUI in Visual Studio, and you can change them in the drop down list or in the configuration manager. Each configuration/platform combination has its own project properties. This is needed so that the options you set for one (for instance, the build directory) don't conflict with the options set for another.

The error you quoted above is because in the project properties there is a property under Linker -> Advanced -> Target Machine that must not conflict with the target platform. That poster was trying to build for the x64 platform, but the target machine property was set to x86. Setting the target machine to x64 would fix the error.

According to MSDN:

MSDN wrote:
Usually, you do not need to specify the /MACHINE option. LINK infers the machine type from the .obj files. However, in some circumstances, LINK cannot determine the machine type and issues a linker tools error LNK1113. If such an error occurs, specify /MACHINE.


now here's the error in my app.

1>c:\users\bahay\documents\visual studio 2010\Projects\waa\Debug\waa.exe : fatal error LNK1120: 1 unresolved externals

This error is given because the linker can't find a certain symbol (such as a variable or function). I hope it's not because of <iostream>. That error should be reported along with a list of the symbols that's giving the linker trouble (LNK2001). Can you show your full code, along with the (1) other linker error? How did you set up your project (did you do empty project or Win32 console)?
Topic archived. No new replies allowed.