error: expected primary-expression before ‘;’ token [closed] - c++

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
First time in a computer science class. First lab assignment. Wrote exactly what the teacher wrote, yet it wont compile, and neither the teacher or I can figure out why. Please help. Thank you.
#include <iostream>
#include <string>
using namespace std;
int main ()
{
int number;
string residence;
//Just an example of a comment
cout << "Hello. Welcome to CSCI-1!" endl;
cout << "Spring 2014" endl;
cout << "please enter a number: " endl;
cin >> number;
cout << "you entered the number: " << number <<endl;
cout<<"Please enter your state of residence: " endl;
cin>>residence;
cout <<"you stated you live in " << residence <<"." <<;
return 0;
}
Errors:
lab01.cpp: In function ‘int main()’:
lab01.cpp:11: error: expected ‘;’ before ‘endl’
lab01.cpp:12: error: expected ‘;’ before ‘endl’
lab01.cpp:14: error: expected ‘;’ before ‘endl’
lab01.cpp:19: error: expected ‘;’ before ‘endl’
lab01.cpp:21: error: expected primary-expression before ‘;’ token

You are missing the << operator before the endl constructs. Change
cout << "Hello. Welcome to CSCI-1!" endl;
To
cout << "Hello. Welcome to CSCI-1!" << endl;

In addition to the missing << before endl (in several lines), you also have an extra one on a line:
cout <<"you stated you live in " << residence <<"." <<;
^^ -- extra!
This will cause you to get another compiler error once you fix the first one. It should be:
cout <<"you stated you live in " << residence <<"." << endl;
or
cout <<"you stated you live in " << residence <<".";

Related

no match for 'operator<<' C++ [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
My program won't run I get an error message saying:
`error: no match for 'operator<<' (operand types are 'std::string' {aka 'std::__cxx11::basic_string<char>'} and '<unresolved overloaded function type>')|`
On the cout << address, " ", street << endl; line
I was using VS2017 but switched to CodeBlocks mid-way through
I have Windows 10 Pro Ryzen 5 2400G, 1060 6gb 16gb ram
Here is my program:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name, city, state, road, country, street;
int address;
cout << "Enter your: Name\n";
cin >> name;
cout << "Enter your Street\n";
cin >> street;
cout << "Enter your: Address\n";
cin >> address;
cout << "Enter your:\n City\n";
cin >> city;
cout << "Enter your: Province/State\n";
cin >> state;
cout << "Enter your: Country\n";
cin >> country;
//Output
cout << name << endl;
cout << address, " ", street << endl;
cout << city, " ", province, " ", country;
}
Thanks in advance!
Your syntax is wrong. You can't use , to chain arguments to cout like that. Instead do:
cout << address << " " << street << endl;
cout << city << " " << province << " " << country;
Your last two statements are syntactically incorrect. They should be as follows -
cout << address<<" "<<street << endl;
cout << city<< " "<< province<<" "<< country;
You probably are trying to use something like python in C++. But obviously that doesn't work. Each time you just have to keep doing cout<< variable1 << " " << variable2<< " "; . This is how chaining works in C++. No shorthand to that
I hope this solves your issue!

What seems to be wrong in my C++ calculator? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
#include <iostream>
using namespace std;
int main()
{
int num1,num2,answer;
char choice = 'Y',input;
while (choice == 'Y' || choice == 'y')
{
cout << "Enter the first number: " << endl;
cin >> num1;
cout << "Enter the second number: " << endl;
cin >> num2;
cout << "What operation would you like to use?" << endl << endl;
cout << "Press [A] if you want to use Addition." << endl;
cout << "Press [S] if you want to use Subtraction." << endl;
cout << "Press [M] if you want to use Multiplication." << endl;
cout << "Press [D] if you want to use Division." << endl;
switch(input)
{
case 'A':
case 'a':
{
answer=num1+num2;
cout << "This is the sum of your equation: " << answer << endl;
break;
}
case 'S':
case 's':
{
answer=num1-num2;
cout << "This is the difference of your equation: " << answer << endl;
break;
}
case 'M':
case 'm':
{
answer=num1*num2;
cout << "This is the product of your equation: " << answer << endl;
break;
}
case 'D':
case 'd':
{
answer=num1/num2;
cout << "This is the quotient of your equation: " << answer << endl;
break;
}
default:
{
cout << "Invalid Operation..." << endl;
break;
}
}
cout << "Do you want to go again? (Y/N) " << endl;
cin >> choice;
}
cout << "See you later." << endl;
return 0;
}
So I just started college about a month and a half ago, and I thought that I'd try out the codes that still hasn't been taught to us. But I ran into a problem, whenever I build my program it shows no error. But it does not do what I had intended it to do, to be a calculator. It immediately jumps to, "Do you want to go again?" After inputting the 2 numbers and it won't let the user even choose an operation let alone calculate it. What seems to be wrong with my code?
[EDIT]
I forgot to put cin >> input; right after asking for which operation to use.
As the comments suggest, you need to get a value for your input variable at some point. I would suggest immediately before the switch that depends on it:
cin >> input; // You forgot to put this line in, I think!
switch(input)
{
...
If you increase the warning level on your compiler, for example using -Wall for GCC, you get a useful warning explaining your problem:
<source>: In function 'int main()':
<source>:8:19: warning: 'input' may be used uninitialized in this function [-Wmaybe-uninitialized]
8 | char choice = 'Y',input;
| ^~~~~
Compiler returned: 0

geany will not let me use the "endl;" when using c++ [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
every time I try to compile it I get an error message along the lines of
"exercise3.cpp:10:49: error: expected ‘;’ before ‘endl’"
and if I add the ; before endl I get the error message
"exercise3.cpp:8:71: error: statement cannot resolve address of overloaded function"
I have no idea what the problem is with this, so any help would be appreciated.
code: (sorry about not being lined right but i assure you that it is.)
#include "iostream"
using namespace std;
int main()
{
cout << "hello there!\n";
cout << "here is 5: "<< 5 << "\n";
cout << "the manipulator end1 wrotes a new line to the screen."; endl;
cout << "here is a very bug number:\t" << 70000 endl;
cout << "here is the sum of 8 and 5:\t" << 8+5 endl;
cout << "heres a fraction:\t\t" << (float) 5/8 endl;
cout << "and a very big number:\t" << (double) 70000*70000 endl;
cout << "you really dont have to type this line XD\n";
cout << "or this one :P cause its not really needed!\n";
return 0;
}
You need to insert << before endl.
cout << "the manipulator end1 wrotes a new line to the screen."; endl;
Should be
cout << "the manipulator end1 wrotes a new line to the screen." << endl;
And so on
You need << before each endl.

C++ free function [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I have the following code
#include "stdafx.h"
#include <iostream>
using namespace std;
#include "graderec.h"
int main( )
{
GradeRecord studentAnn("45-2791", 14, 49);
GradeRecord studentBob("67-5803",25, 50);
int bobsUnits;
int bobsGradePoints;
int annsUnits = 4;
int annsGradePoints = 16;
cout << "Ann's Grade Information:" << endl;
studentAnn.writeGradeInfo();
cout << endl;
cout << "Bob's Grade Information:" << endl;
studentBob.writeGradeInfo();
cout << endl;
cout << "Enter Bob's units: ";
cin >> bobsUnits;
cout << "Enter Bob's grade points: ";
cin >> bobsGradePoints;
cout << endl;
cout << "Bob's Grade Information:" << endl;
studentBob.updateGradeInfo(bobsUnits, bobsGradePoints);
studentBob.writeGradeInfo();
cout << endl;
cout << "Ann's Grade Information:" << endl;
studentAnn.updateGradeInfo(annsUnits, annsGradePoints);
studentAnn.writeGradeInfo();
system("PAUSE");
return 0;
}
void asterisks()
{
cout << "************************************************************************" << endl;
}
I need to use a free function to display about 60 asterisks where I have cout << endl. I followed the example that I was giving but can't get it to work.
The code below is the example that I was given on how a free function looks.
void companyBanner()
{
cout << *************************** << endl;
cout << ** Tech Guys LLC ** << endl;
cout << *************************** << endl;
cout << endl;
}
Updatea: Got it working, thanks for the help everyone. I rewrote the free function and added asterisks() above the main again and it worked. Must have been something in the free function that was causing it to not work.
You should call the function you defined otherwise it will never be executed.
You should also place either a declaration or the whole definition of the function before you call it for the first time.
String literals should be enclosed in double quotes ".
'Doesn't work' is too vague for us to help you. My attempt for now is that you have not prototyped your asterisks() function. Put void asterisks(); above your main.
If I understand the question (please tell me if I'm wrong), just replace cout << endl; by a call to your function: asterisks().
Also, either move the function asterisks before your main, or add the prototype void asterisks(); above the main.

What are the errors in this code? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
void main (void)
{
char name [2] [30], number [2] [10];
char << "Please type your first name, a blank, and last name) << endl;
cin >> name;
cout << "Name=" <<name << endl;
cout << "Please type a number, press the return key, and another number << endl;
cin >> number [0] >> endl;
cout << number << endl;
}
Too many to mention, but we're not here to act as a homework service. Examine the output of your compiler then tackle them one at a time:
qq.cpp:4:13: warning: missing terminating " character
qq.cpp:4: error: missing terminating " character
qq.cpp:7:13: warning: missing terminating " character
qq.cpp:7: error: missing terminating " character
qq.cpp:1: error: ‘::main’ must return ‘int’
qq.cpp: In function ‘int main()’:
qq.cpp:4: error: expected unqualified-id before ‘<<’ token
qq.cpp:6: error: ‘cout’ was not declared in this scope
qq.cpp:6: error: ‘endl’ was not declared in this scope
qq.cpp:8: error: ‘cin’ was not declared in this scope
At a bare minimum:
No using clause or std:: prefixes.
char is not a stream.
No closing quotes on some of the string literals.
There is a parenthesis instead of a double quotation mark at the end of "Please type your first name, a blank, and last name)
You don't end the string with a " as in
char << "Please type your first name, a blank, and last name) << endl;
and
cout << "Please type a number, press the return key, and another number << endl;
it should be:
int main (void)
{
char name [2] [30], number [2] [10];
char << "Please type your first name, a blank, and last name)" << endl;
cin >> name;
cout << "Name=" <<name << endl;
cout << "Please type a number, press the return key, and another number" << endl;
cin >> number [0] >> endl;
cout << number << endl;
return 0;
}
char << "Please type your first name, a blank, and last name) << endl;
and
cout << "Please type a number, press the return key, and another number << endl;
are both missing end double quotes
char << "Please type your first name, a blank, and last name)" << endl;
cout << "Please type a number, press the return key, and another number" << endl