473,386 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

int main error

I am very new with C++
I have an assignment that follows

Write a C++ program containing a for loop to print the message
DooBeeDooBeeDooBeeDooBeeDooBeeDooBee Do

My code so far is

#include <iostream>
using namespace std;

int main ()
{
int Doo;
int Bee;

for (int Doo = 0; Doo < 6; Doo++)
for (int Bee = 0; Bee < 6; Bee++)
std::cout << "Bee"<<std::;
std::cout << "Doo"<<std::;
}




My error messages follows

DooBee.cpp: In function âint main()â:
DooBee.cpp:11: error: expected unqualified-id before â;â token
DooBee.cpp:12: error: expected unqualified-id before â;â token
Oct 7 '09 #1
15 5413
weaknessforcats
9,208 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. std::cout << "Bee"<<std::;
Did you mean:

Expand|Select|Wrap|Line Numbers
  1. std::cout << "Bee"<<std::endl;
?

Also, the int Bee in main() is a different variable from the int Bee that's inside the for loop.
Oct 7 '09 #2
I didn't mean endl I need it all on one line.

What do you suggest to fix the main ()
Oct 7 '09 #3
weaknessforcats
9,208 Expert Mod 8TB
Take the word int out of your for loops.

What this is doing is creating another int named Bee that is local to the loop. This local variable is hiding the one you defined outside the loop. Do this for both variables.
Oct 7 '09 #4
Done still got these three messages


DooBee.cpp: In function âint main()â:
DooBee.cpp:11: error: expected unqualified-id before â;â token
DooBee.cpp:12: error: expected unqualified-id before â;â token
Oct 7 '09 #5
New Code is

#include <iostream>
using namespace std;

int main()
{
int Doo;
int Bee;

for (Doo = 0; Doo < 6; Doo++)
for (Bee = 0; Bee < 6; Bee++)
std::cout << "Bee"<<std::;
std::cout << "Doo"<<std::;
}
Oct 7 '09 #6
drhowarddrfine
7,435 Expert 4TB
Shouldn't it be this? (It should compile but I know it won't do what he wants.)
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int
  5. main()
  6. {
  7. int Doo;
  8. int Bee;
  9.  
  10. for (Doo = 0; Doo < 6; Doo++)
  11. for (Bee = 0; Bee < 6; Bee++)
  12. cout << "Bee";
  13. cout << "Doo";
  14. }
  15.  
Oct 7 '09 #7
myusernotyours
188 100+
A loop without braces is only done for the next one line of code. If you want it done for two or more lines you have to enclose your loop in braces;
Expand|Select|Wrap|Line Numbers
  1. for(int i = 0 ; i < 10 ; i++)
  2. std::cout << i;
  3. std::cout << i;
  4.  
is different from
Expand|Select|Wrap|Line Numbers
  1. for(int i = 0 ; i < 10 ; i++){
  2. std::cout << i;
  3. std::cout << i;
  4. }
  5.  
Regards,

Alex.
Oct 7 '09 #8
I am sorry for the newbish question but after i compile it how do I run it
Oct 7 '09 #9
Banfa
9,065 Expert Mod 8TB
That rather begs the question how are you compiling it?

From the command line? From a IDE? If its from an IDE which IDE (for example Visual C++, Eclipse, Dev-C++, CodeBlocks)?

On what operating system?
Oct 7 '09 #10
Command Line inside WinSCP
Windows 64bit vista
Oct 7 '09 #11
Banfa
9,065 Expert Mod 8TB
Which compiler are you using?

Anyway regardless of that the result of a compilation, assuming no errors, should be an object file, extension .obj on a Windows machine. You would then link the object with libraries and other objects to produce a executable file, extension .exe.

However most modern compiler interfaces are actually interfaces onto the entire tool chain. This means you can initiate a compile followed by a link from a single command.

If you have a .exe in the directory you are compiling in then that is what has happened. If you only have a .obj then you have compiled but not linked. In the latter case try telling the compiler you would like an executable output, normally with the -o <outputfilename> switch. Give your output file name a .exe extension (this works with gcc/g++ I am not so sure about the Microsoft compiler).
Oct 7 '09 #12
Oh im sorry im not trying to run it independent. I just want to check it in the command line to make sure its working.
Oct 8 '09 #13
whodgson
542 512MB
Do you mean the last Do has to have a space in front of it?
If not something like this may serve..
Expand|Select|Wrap|Line Numbers
  1. string s1="DooBee";
  2. string s2="Do";
  3.     for(int i=0;i<6;++i)
  4.     if(i==5)cout<<s2;
  5.     else cout<<s1;
otherwise the second last line should read:
Expand|Select|Wrap|Line Numbers
  1. if(i==5)cout<<" "<<s2;
Oct 8 '09 #14
Excellent responses and suggest, I will be on these forums for a long time to come
Oct 8 '09 #15
Last Question for this topic I promise lol.

The program compiles and runs smooth but it prints out at the very beginning of my command line.

Is there a way to put in a endline to fix this
Oct 8 '09 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

26
by: Bill Cunningham | last post by:
I've read that the only parameters that main takes other than a void is this main(int argc,char *argv) I may be correct on this. I want to take from the command line prompt 2 doubles, pass the...
2
by: Legendary Pansy | last post by:
Hello, I'm trying to accomplish the impossible by trying to do something equivalent of this example found here http://www.c-sharpcorner.com/Code/2003/Dec/DialogTutorial.as Starting with "Listing...
17
by: Fred Nelson | last post by:
Hi: I'm trying to implement an overall error handler in my VB.NET windows application. I need to place an "On Error Goto" in "Sub Main". I have tried to create a Sub Main and have had no...
17
by: GS | last post by:
the main menu in the application seemed to disappeared all together until I click on an control and select mainmenu1 in designer. then the mainmenu1 displays where it should be but running it or...
2
by: =?ISO-8859-15?Q?Luigi_Malag=F2?= | last post by:
Hello, i'm having a problem with "multiple definition error" linking a library. I have a program with a main. I have another program with classes and a main too. I created a library of the second...
6
by: fatwallet961 | last post by:
is the main function in python is exact compare to Java main method? all execution start in main which may takes arguments? like the follow example script - def main(argv): ...
6
by: unlikeablePorpoise | last post by:
I am trying to get JPype to pass a String into a Java class main function. Demonstration code below: =============JAVA============ package com; public class JPypeTest { public static void...
70
by: junky_fellow | last post by:
Guys, If main() calls some function func() and that function returns the error (errno), then does it make sense to return that value (errno) from main. (in case main can't proceed further) ? ...
11
by: aarklon | last post by:
Hi all, I have heard many discussions among my colleagues that main is a user defined function or not. arguments in favour:- 1) if it is built in function it must be defined in some header...
17
by: mike-yue | last post by:
and, Is it possible to call one main function from another main function? Thanks guys.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.