#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{//variable names
int Int1, Int2, Int3, sum, average, product;
//takes user input
printf("input three different integers: ");
scanf("%d%d%d", &Int1,&Int2,&Int3);
//equation process
sum = Int1 + Int2 + Int3;
average = sum / 3;
product = Int1 * Int2 * Int3;
cout<<"Enter Int1 : ";
cin>>Int1;
cout<<"Enter Int2 : ";
cin>>Int2;
cout<<"Enter Int3 : ";
cin>>Int3;
if(Int1>=Int2)
{
if(Int1>=Int3)
{
cout<<"Largest Number Is : "<<Int1;
if(Int2<=Int3)
cout<<"Smallest Number Is : "<<Int2;
else
cout<<"Smallest Number Is : "<<Int3;
}
else
{
cout<<"Largest Number Is : "<<Int3;
cout<<"Smallest Number Is : "<<Int2;
}
}
else
{
if(Int2>=Int3)
{
cout<<"Largest Number Is : "<<Int2;
if(Int1<=Int3)
cout<<"Smallest Number Is : "<<Int1;
else
cout<<"Smallest Number Is : "<<Int3;
}
else
{
cout<<"Largest Number Is : "<<Int3;
cout<<"Smallest Number Is : "<<Int1;
}
}
//prints results
printf("Sum is %d\nAverage is %d\nProduct is %d\n", sum, average, product);
return 0;
}
im trying to make it so it tells me the smallest and largest of the 3 integers but i keep getting the following error:
error C2065: 'cout' : undeclared identifier
error C2065: 'cin' : undeclared identifier
#include <iostream>
using namespace std;
// etc...
Since you're using iostreams anyway, rewrite the printf and scanf calls at the beginning and end of the main function using cout and cin. Also consider not including stdafx.h, and if you don't need to support Unicode command-line arguments (chances are you don't), change _tmain to main and _TCHAR to char.
int _tmain(int argc, _TCHAR* argv[])
{//variable names
int Int1, Int2, Int3, sum, average, product;
//takes user input
printf("input three different integers: ");
scanf("%d%d%d", &Int1,&Int2,&Int3);
//equation process
sum = Int1 + Int2 + Int3;
average = sum / 3;
product = Int1 * Int2 * Int3;
//prints results
printf("Sum is %d\nAverage is %d\nProduct is %d\n", sum, average, product);
return 0;
}
okay lets start over my assignment is to add to this so it also tells me the largest and smallest of the integers. now im not asking for it to be done for me but i know next to nothing about programming but im assuming i need to do an If statement similar to the above one but one that doesnt force me to change stdafx.h and such
okay lets start over my assignment is to add to this so it also tells me the largest and smallest of the integers. now im not asking for it to be done for me but i know next to nothing about programming
Then take our advice.
If you want to be a programmer, you should know what is standard and non-standard.
but im assuming i need to do an If statement similar to the above one but one that doesnt force me to change stdafx.h and such
There is no such file as "stdafx.h" in standard C++. So asking us to "not touch it" doesn't make sense. To many here, it doesn't even exist, and it will just interfere with you actually writing the program correctly.
Second, the entry point function for C++ programs is main(), not tmain(). I know you use Microsoft compilers, but you should know how to write your programs, independent of whether you're using a Microsoft compiler or not.
The following is a correct C++ program that will compile under any ANSI compliant C++ compiler.
Code:
#include <cstdio>
int main()
{
int Int1, Int2, Int3, sum, average, product;
//takes user input
printf("input three different integers: ");
scanf("%d%d%d", &Int1,&Int2,&Int3);
//equation process
sum = Int1 + Int2 + Int3;
average = sum / 3;
product = Int1 * Int2 * Int3;
//prints results
printf("Sum is %d\nAverage is %d\nProduct is %d\n", sum, average, product);
return 0;
}
Some things:
Turn off precompiled headers in your project settings. Get rid of the TCHAR stuff and _tmain() so that you know what a standard C++ program consists of.
Once you know what a standard C++ program is supposed to look like, then you can go and try precompiled headers, TCHAR or whatever other Microsoft specific things you want to try.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; September 25th, 2007 at 10:42 PM.
Bookmarks