WillMcc 0 Newbie Poster

Not quite sure what a++ is or char.... soo... yeah... But I think I figured out what they were talking about...

for example:

int apples = 1, passes = 0, fails = 0, result;

while (apples <= 10)
{
cout>>"Enter result" : ";
cin<< result;

if (result == 1)
passes = passes +1;
else 
failures = failures +1;

Kinda forgot about learning the whole if/else.

WillMcc 0 Newbie Poster

Okay, so I'm a bit confused... here are my instructions for making a program:

1. Input each test result (i.e. a 1 or a 2). Display the message " Enter result" on the screen each time the program requests another test result.

2. Count the number of test results of each type.

I have no idea how to do number 2 the only thing I know how to do is like... record a variable. (using the cin>>) I don't know how I would actually count how many times something was entered.

Any help? I think the book I'm using is crazy and asking me to make programs of stuff I haven't learned yet.. (Awesome book).

WillMcc 0 Newbie Poster

The basic purpose of the program is for the user to enter 10 numbers, then the program to add them all up as they are entered until it gets to 10 numbers entered which at that point it divides total by 10.

#include "stdafx.h"
#include <iostream>

using namespace std;

int main()
{
int counter, grade, total, average;

total = 0;
counter = 1;

while (counter <= 10) {
	cout>> "Enter Number: ";
		cin>>grade;
		total = total + grade;
		counter = counter + 1;
}
average = total / 10;
cout << " The average of the numbers entered is: " << average << endl;

return 0;
}

here is the error message:


------ Build started: Project: Usiing while, Configuration: Debug Win32 ------
Compiling...
Usiing while.cpp
.\Usiing while.cpp(16) : error C2784: 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,unsigned char &)' : could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::ostream'
C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(1021) : see declaration of 'std::operator >>'
.\Usiing while.cpp(16) : error C2784: 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,unsigned char &)' : could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::ostream'
C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(1021) : see declaration of 'std::operator >>'
.\Usiing while.cpp(16) : error C2784: 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,unsigned char &)' : could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::ostream'
C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(1021) : see declaration of 'std::operator >>'
.\Usiing while.cpp(16) : error C2784: 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,unsigned char &)' : could …

WillMcc 0 Newbie Poster

Mmmm, Yeah I'm blind apparently.

Thank you, this is handled.

WillMcc 0 Newbie Poster

Okay, got it. Still getting an error, I'm not sure if I'm completely blind and somewhere in the script I wrote num(space)1 or num(space)2 but I don't see anything like that, anyway here is the updated code:

#include "stdafx.h"
#include <iostream>

using namespace std;

int main()
{
	int num1;
	int num2;

	cout << "Enter two integers, and I will tell you/n"
		<< "the relationship the satisfy: ";
cin >> num1 >> num2; 

if (num1 == num2)
cout << num1 << "is equal to" << num2 << endl;


if (num1 != num2)
cout << num1 << "is not equal to" << num2 << endl;

if (num1 < num2)
cout << num1 << "is less than" << num2 << endl;

if (num1 > num2)
cout << num1 << "is Greater than" << num2 << endl;

if (num1 <= num2)
cout << num1 << "is less than or equal to" << num << endl;

if (num1 >= num2)
cout << num1 << "is greater than or equal to" << num2 << endl;

return 0;

}

And the error message:

------ Build started: Project: Blarg, Configuration: Debug Win32 ------
Compiling...
Blarg.cpp
.\Blarg.cpp(31) : error C2065: 'num' : undeclared identifier
Build log was saved at "file://c:\Documents and Settings\Owner\My Documents\Visual Studio 2008\Projects\Blarg\Blarg\Debug\BuildLog.htm"
Blarg - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

WillMcc 0 Newbie Poster

Awesome, works as it should now. Thanks a lot.

WillMcc 0 Newbie Poster

I'm just basically reading a book and messing around with the scripts they give me so I can understand what they're talking about, and here is the script (essencially word for word) however isn't working. What the program is supposed to do is (for example:)

"Enter two integers, and I will tell you the relationship they satisfy: 3 7

3 is not equal to 7
3 is less than 7
3 is less than or equal to 7"

Here is the code i'm messing with:

// Blarg.cpp : main project file.

#include "stdafx.h"
#include <iostream>

using namespace std;

int main()
{
	int num1;
	int num2;

	cout << "Enter two integers, and I will tell you/n"
		<< "the relationship the satisfy: ";
cin >> num1 >> num2; 

if (num1 == num2)
cout << num1 << "is equal to" << num2; endl;


if (num1 != num2)
cout << num1 << "is not equal to" << num2; endl;

if (num1 < num2)
cout << num1 << "is less than" << num2; endl;

if (num1 > num2)
cout << num1 << "is Greater than" << num2; endl;

if (num1 <= num2)
cout << num1 << "is less than or equal to" << num2; endl;

if (num1 >= num2)
cout << num1 << "is greater than or equal to" << num2; endl;

return 0;

}

And here is the error message:

------ Build started: Project: Blarg, Configuration: Debug Win32 ------
Compiling...
Blarg.cpp
.\Blarg.cpp(18) : …

WillMcc 0 Newbie Poster

Awesome, That seemed to solve it. One last question - When I debug it, what do I do to have it stay up (rather than adding Variable + Variable then getting total and closing)

Hope that made sense.

WillMcc 0 Newbie Poster

Got it, I'll definitly check out the rules & regulations right after this. Here is the error message I got after changing the script:


------ Build started: Project: Test 2, Configuration: Debug Win32 ------
Compiling...
Test 2.cpp
.\Test 2.cpp(3) : warning C4627: '#include <iostream>': skipped when looking for precompiled header use
Add directive to 'stdafx.h' or rebuild precompiled header
.\Test 2.cpp(22) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
Build log was saved at "file://c:\Documents and Settings\Owner\My Documents\Visual Studio 2008\Projects\Test 2\Test 2\Debug\BuildLog.htm"
Test 2 - 1 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

WillMcc 0 Newbie Poster

As the title says, more or less. I'm just trying to make a program basically (Variable) + (Variable) = (Total)

Here is the script:

// Variable + Variable = Total.cpp : main project file.

#include "stdafx.h"

using namespace System;

void main()
{
    float num1;
    float num2;
    float total;

    cout<<"enter a value for the first variable:";
    cin>> num1;
    cout<<"enter a value for the second variable:";
    cin>> num2;

    total = num1 + num2;

    cout<<"The sum of the numbers =" << total;
}

I think that #include "stdafx.h" is a template from the IDE that I'm using (Microsoft Visual C++ 2008 Express Edition)

Here is the error that I get when I try to compile it...:

------ Build started: Project: Variable + Variable = Total, Configuration: Debug Win32 ------
Compiling...
Variable + Variable = Total.cpp
.\Variable + Variable = Total.cpp(13) : error C2065: 'cout' : undeclared identifier
.\Variable + Variable = Total.cpp(14) : error C2065: 'cin' : undeclared identifier
.\Variable + Variable = Total.cpp(15) : error C2065: 'cout' : undeclared identifier
.\Variable + Variable = Total.cpp(16) : error C2065: 'cin' : undeclared identifier
.\Variable + Variable = Total.cpp(20) : error C2065: 'cout' : undeclared identifier
Build log was saved at "file://c:\Documents and Settings\Owner\My Documents\Visual Studio 2008\Projects\Variable + Variable = Total\Variable + Variable = Total\Debug\BuildLog.htm"
Variable + Variable = Total - 5 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Any help is appreciated, again take into account that I really don't have any …