|
Please help me as I am getting 8-12 compiler errors & suck at C++. I just want to pass this class & teacher is a jerk with no help available. What's wrong with this? I will be eternally grateful.
//******************************************************
// Filename: D4_Lab_02.cpp
// Purpose: Fix the Errors
// Author: Melissa
// Revised: April 22, 2007
//******************************************************
#include<iostream>
#include<string>
using namespace std;
void pause(void);
#define PI=3.1415
int twiceage
string last_name;
string lastname_length;
string age;
//******************************************************
// main
//******************************************************
int main(void)
{
cout << "INPUT ITEMS\n";
cout << "\nEnter your last name ----->: ";
cin >> last_name;
cout << "\nEnter how many letters are in your last name --->: ";
cin >> lastname_length;
cout << "\nEnter your age ----------->: ";
cin << age;
cout << "\nOUTPUT ITEMS\n";
cout << "\nYou said your last name was: " << last_name;
cout << "\n\nYour last name has ";
cout << lastname_length<< " letters in it.";
cout << "\n\nYour age is: " << age;
twiceage = age*2
cout << "\n\nTwice your age is: " << age*2;
cout << "\n";
for (count=0; count <5; count++)
{
cout << "\nHi Mom!";
}
cout << "\n\nThe area of a circle with a 6 inch diameter is: ";
cout << 3 * 3 * PI;
pause(void);
return 0;
}
//******************************************************
// pause
//******************************************************
void pause(void)
{
char pause;
cout << "\n\n\nHit Enter Key to Continue: ";
cin.get(pause);
cin.get(pause);
return;
}
//******************************************************
// End of Program
//******************************************************
Melissa
|
|
|
|
|
1. What are the errors you're getting? It's hard to tell you the source if we don't know what they are
2. You have several syntactical errors:
a. int twiceage needs a semicolon after it.
b. cin << age; should have the pipe pointing the other direction
c. twiceage = age*2 needs a semicolon at the end
d. technically, you don't need arguments to the pause() function, and using pause(void) in the function definition is an error - if you're going to provide a type specifier you need to provide a variable name too (the declaration at the top is fine, though). So for pause, it'd be better just to declare the function as "void pause()"
Try fixing those and let us know what further errors you get.
------------
Cheers,
Patrick
|
|
|
|
|
Thank you, Patrick.
Now it's down to 8 errors, so that is a step in the right direction- yeah!
What it's saying is...
in function 'int main()'
43 no match for 'operator*' in 'age*2'
45 no match for 'operator*' in 'age*2'
48 overloaded function with no contextual type information
48 missing'>' to terminate the template argument list
48 could not convert 'count<5>' to 'bool'
48 no post-increment operator for type
55 expected primary-expression before '=' token
57 expected primary-expression before "void"
Also, could you explain how to arrive at the answer of 9 from this expression?
29 >= 25 ? 7 + 2 : 14 - 9
Wicked thanks a lot for any & all help!
Melissa
|
|
|
|
|
wertyou wrote: 43 no match for 'operator*' in 'age*2'
Whoops. Missed this. age needs to be declared as an int; you're declaring it as a string. cin will do the work for you of converting the input to the correct type. If it happens that the input can't be converted to an integer, the value will be undefined and you'll likely get garbage when you do the multiplication (this depends on the compiler - some compilers will default the int to 0 for you, but don't depend on that behavior).
What that error is telling you is that there is no 'multiply' operator defined between a string and an integer, which is true.
wertyou wrote: 48 overloaded function with no contextual type information
48 missing'>' to terminate the template argument list
48 could not convert 'count<5>' to 'bool'
48 no post-increment operator for type
Simple - the 'count' variable isn't defined anywhere. Simply define an 'int count;' somewhere.
See if that takes care of lines 55 and 57 also.
wertyou wrote: Also, could you explain how to arrive at the answer of 9 from this expression?
29 >= 25 ? 7 + 2 : 14 - 9
That's called 'ternary' notation - the stuff before the ? is evaluated to true or false, and if it is true, the stuff between the ? and : is returned; if it evaluates to false, the stuff after the : is returned.
In this case, 29 is indeed greater than or equal to 25, so the operation returns "7 + 2" which equals 9.
------------
Cheers,
Patrick
|
|
|
|
|
Thank you for the reply. I did what you said and also added two lines about asking the persont to input a count number. So far, there are only 2 errors left! It's in line 58 and 60, saying
expected primary-expression before '=' token
and
expected primary-expression before '=' void
It's regarding the last part about the 3*3*PI -- am I defining PI wrong?
I kind of understand what you're saying about the math expression - I thought it was the one that was 1 for true and 0 for false- how can I tell them apart?
Thanks again.
Melissa
|
|
|
|
|
wertyou wrote: It's in line 58 and 60, saying
expected primary-expression before '=' token
and
expected primary-expression before '=' void
Whoops, missed that one too.
You're using this to define PI:
#define PI=3.14159
#define's don't use the equals sign - just a space, like this:
#define PI 3.14159
What you need to know here is that the compiler has a step called "Preprocessing" in which it does literal string replacement of all #define's with their values - it actually replaces those physical characters before compiling. So what the compiler is actually seeing at 3*3*PI looks like this:
cout << 3 * 3 * =3.14159;
which obviously is nonsense. That's the cause of the other error about void, too, because the compiler is getting totally confused by that equals sign.
wertyou wrote: I kind of understand what you're saying about the math expression - I thought it was the one that was 1 for true and 0 for false- how can I tell them apart?
No, the ternary operator operates on straight booleans. It will, however, interpret 1 as true and 0 as false, but those really have little to do with how the operator works.
It's pretty simple:
return CONDITION ? TRUE_EXPRESSION : FALSE_EXPRESSION;
The operator evaluates CONDITION to be true or false and returns the corresponding expression. Then, that expression is evaluated, no matter what it is. I could be a function call; it could be an integer; it can be any valid expression, really.
So, the following are all valid uses of the ternary operator:
int result = (true) ? 1 : 0; // returns 1
string result = (1) ? "yes" : "no"; // returns "yes"
string result = (0) ? "no" : "yes"; // returns "no"
int result = (29 >= 25) ? 7 + 2 : 0; // returns 7 + 2, which evaluates to 9.
And so forth.
------------
Cheers,
Patrick
|
|
|
|
|
Thanks a lot, Patrick. It seems a lot easier to understand about the ternary stuff. Also, thanks for the code help, too.
Melissa
|
|
|
|
|
Glad I could help!
------------
Cheers,
Patrick
|
|
|
|
|
I still have one error in this code and it's the following:
57 no match for 'operatr >>' in 'std::cin>> 2.8273...
and then 22 errors that are exactly the same
std:basic_istream<_CharT, _Traits>& std::basic_istream<chart, _traits="">::operator>>
Do you know what this means?
Sorry for asking again. I asked this last question to the instructor and he hasn't replied. The lab is already late.
#include<iostream>
#include<string>
using namespace std;
void pause(void);
#define PI 3.1415
int main(void)
{
cout << "\n\nThe area of a circle with a 6 inch diameter is: ";
cin >> 3 * 3 * PI;
pause(void);
return 0;
}
Melissa
|
|
|
|
|
Hi Melissa,
cin has to pipe into a declared variable; in the example you've posted, it's piping into an actual number. In that example though, it looks like you're just trying to write out what the diameter of a circle is though - so you'd change the cin to a cout.
cin is used like this:
int main(void)
{
int someValue;
cout << "Enter a number: ";
cin >> someValue;
pause(void);
return 0;
}
------------
Cheers,
Patrick
|
|
|
|
|
Thank you very much, Patrick. Now it's compiling without any problems. Oh, and I'm just now realizing that I posted my question in the wrong place- I thought the # meant any and all C question- whoops!
Thanks again.
Melis
|
|
|
|
|
No problem
wertyou wrote: Oh, and I'm just now realizing that I posted my question in the wrong place- I thought the # meant any and all C question- whoops!
Good thing you did! I don't usually go over to the C++ forum so I'd never have seen your question!
Come back soon!
------------
Cheers,
Patrick
|
|
|
|
|
Hi
1. How to enable internet explorer's "Disable script debugging option" thru code?
Is there any API which will do this operation, if so, Please give me some example code
2. Also I am doing design document update for my code, I am in need of putting class diagram and class description. I could able to create class diagram from VS studio, but i am not able generate class descriptions (like variable_name type modifier description) for all the variables,properties and functions. I can able to see those details by right click on the class diagram and class view details, but it is not allowing me to copy all the details at a time. But i am able to copy one at a time. Is there any simple way to get all class description as like as shown in class details window. (I am working in C#). so that i can copy and paste it in the document. ( i very much required this, because i have 100s of classes and its variables )
sry 2nd is repeated qn., where nobody replied for that
Thanks
srini
|
|
|
|
|
1 - Do you mean C# code, in a client side app, or javascript through a web app ? The former may be possible.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
yes. thru C# code, it is windows application not web..
Thanks
Srini
|
|
|
|
|
hi,
My problem is that my boss told me he didn't want to everytime add a new row to datagridview he must provide new values for new row's cell. Actually. in an added row, only one or two cell need changing values, others are unchangeable. He did want to copy an existing row and paste as new row as well as change the needed values without appearing errors
I tried to use getClipboardContent() method to manually add values of an existing row to a new row but its not working. I think everybody here could help me solve this by showing me how to copy a gridview row and paste as a new row without errors or suggest me a new way to solve this. Thanks in advance
[my code]
string[] str;<br />
private void copyToolStripMenuItem_Click(object sender, EventArgs e)<br />
{<br />
DataObject obj = dataGridView1.GetClipboardContent();<br />
str = obj.GetText(TextDataFormat.CommaSeparatedValue).Substring(1).Split(',');<br />
}<br />
<br />
private void pasteToolStripMenuItem_Click(object sender, EventArgs e)<br />
{<br />
try<br />
{<br />
DataGridViewRow dgvRow = dataGridView1.Rows[0];<br />
for (int i = 1; i < str.GetLength(0); i++)<br />
dgvRow.Cells[i].Value = str[i];<br />
dataGridView1.Rows.Add(dgvRow);<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show(ex.Message);<br />
}<br />
}
It seem to be a solution or an answer.
|
|
|
|
|
Plz help me....
I want to append two or more WMV Files in C#... How can i do that????
aLi
|
|
|
|
|
Google the WMV file format. You'll need to extract the data from both files and append them together with a new WMV header.
|
|
|
|
|
hi
i have an app that work with Sql server 2005 Database,for insert to it i used Stored Procedure as "sp_AddToPersons" and use this code to insert action :
SqlConnection con = new SqlConnection(Properties.Settings.Default.ExpressDBConnectionString);<br />
SqlCommand cmdInsert = new SqlCommand();<br />
cmdInsert.CommandType = CommandType.StoredProcedure;<br />
cmdInsert.CommandText = "sp_AddToPersons";<br />
cmdInsert.Connection = con;<br />
<br />
SqlParameter p1 = new SqlParameter("@personName", this.txt_name.Text);<br />
SqlParameter p2 = new SqlParameter("@personFamily", this.txt_family.Text);<br />
SqlParameter p3 = new SqlParameter("@personTel", this.txt_tel.Text);<br />
SqlParameter p4 = new SqlParameter("@personAddress", this.txt_address.Text);<br />
<br />
cmdInsert.Parameters.Add(p1);<br />
cmdInsert.Parameters.Add(p2);<br />
cmdInsert.Parameters.Add(p3);<br />
cmdInsert.Parameters.Add(p4);<br />
<br />
try<br />
{<br />
if (con.State == ConnectionState.Closed)<br />
con.Open();<br />
<br />
cmdInsert.ExecuteNonQuery(); <br />
}<br />
catch (SqlException se)<br />
{<br />
MessageBox.Show(se.ToString());<br />
}<br />
finally<br />
{<br />
if (con.State == ConnectionState.Open)<br />
con.Close();<br />
cmdInsert.Dispose();<br />
}
but the table in my database was not update and don't insert to it, how to solve my problem ?
|
|
|
|
|
I don't see anything obviously wrong with that code. What about the code of the stored procedure?
Also, you should avoid naming stored procedures starting with "sp". This is because SQL Server has a number of stored procedures beginning with sp and if you call one it will look in the master database first and might ignore your stored procedure. At least, that was the case with previous versions of SQL Server.
|
|
|
|
|
Colin Angus Mackay wrote: Also, you should avoid naming stored procedures starting with "sp".
Actually "sp" works fine, but "sp_" is the special prefix that is used for system procedures. Starting a procedure name with "sp_" does not only risk a name conflict with the system procedures, it will also prevent caching of the execution plan for the procedure. The database looks for a cached execution plan for the procedure in the master database, and as it doesn't find it there, it will always be recompiled, eventhough there might be a cached execution plan in your database.
---
single minded; short sighted; long gone;
|
|
|
|
|
I'm using FileSystemWatcher class to be notified upon any change in the file system of my server. But I wonder how I can obtain the information about the user that made the change. Any idea?
|
|
|
|
|
You don't. The FSW doesn't supply that kind of information.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
i dont think FileSystemWatcher can do that
Keshav Kamat
India
|
|
|
|
|
Well is there any other way to get the information I need?
|
|
|
|