Welcome
Welcome to the forums of AntiRTFM's Absolute N00b Spoonfeed C++ Tutorials!

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. Registration is fast, simple, and absolutely free, so please, <a href="/profile.php?mode=register">join our community today</a>!

Debug Project 2 (Easy)

Think you can spy out that little nasty bug? Try debugging some code in here

Debug Project 2 (Easy)

Postby Marss++ on Mon Jul 21, 2008 10:50 pm

Here is another code. Very simple.


Object of the code is to print out on the screen
"I love Marss++ and I love programming"


Here's the code:

Code: Select all

#include "stdafx.h"
#include <iostream>
using namespace std;

int main()
{
   cout << "I love Marss++;
   cout << "and I love programming" << endl;

   return 0;
}



When you figure it out. Write a new program that does this and then tell why this wouldn't work.
I'm a 15 year old kid who has his heart set on Programming.

Came here hoping to help so if you have any questions just ask!
Marss++
 
Posts: 149
Joined: Fri Jul 18, 2008 3:20 pm

Postby asib on Wed Jul 23, 2008 12:34 am

You need to change :

Code: Select all
cout << "I love Marss++;


You need to put in a space after the word, then close quotes, like so :

Code: Select all
cout << "I love Marss++ ";


It wouldn't work because it would throw an error, after the next quote. You also need to add the space so it spaces out the words.
asib
 
Posts: 86
Joined: Tue Jul 22, 2008 9:15 pm

Postby Marss++ on Thu Jul 24, 2008 12:31 pm

Your right. Great job.

Keep up the good work.
I'm a 15 year old kid who has his heart set on Programming.

Came here hoping to help so if you have any questions just ask!
Marss++
 
Posts: 149
Joined: Fri Jul 18, 2008 3:20 pm

Re: Debug Project 2 (Easy)

Postby Argio on Mon Dec 01, 2008 3:00 am

Well its as difficult as it says. Lawl

Code: Select all
#include "stdafx.h"
#include <iostream>
using namespace std;

int main()
{
   cout << "I love Marss++;
   cout << "and I love programming" << endl;

   return 0;
}


Do you see the error on line 7?
Code: Select all
   cout << "I love Marss++;

Tho solution you ask Argio???

Code: Select all
   cout << "I love Marss++";


Wait a sec Argio, how the hell does this work?

Well, if I had cout << "I love Marss++; I would be turning the rest of my code on the line into what my program was going to output thus making ; not work because it has became part of output. but then the output can not execute without the ; so the program won't work. D:
I love C++, for reasons I have yet to discover.
All the haters love me so lovers stop hating.
Image
User avatar
Argio
 
Posts: 21
Joined: Fri Jun 20, 2008 5:04 am
Location: Utah. I am jewish.

Re: Debug Project 2 (Easy)

Postby Doctor Salt on Sun Jan 18, 2009 4:03 pm

You would also need to use one of the many ways to stop the program, else it would instantly exit.
I'm a 15 year old kid who has his heart set on Programming, almost as much as Marss++.......

Came here hoping to ask more questions so if you have any free time just say!
Doctor Salt
 
Posts: 147
Joined: Wed Jul 30, 2008 3:32 pm

Re: Debug Project 2 (Easy)

Postby SinZombie on Tue Mar 31, 2009 4:52 pm

People! Forget
Code: Select all
char f;
cin >> f;

for the programm to wait. Use
Code: Select all
#include <conio.h>

void main()
{
  getch();
}

getch stands for Get Character. It continues the programm when any key is pressed. :!:
SinZombie
 
Posts: 4
Joined: Tue Mar 31, 2009 4:46 pm

Re: Debug Project 2 (Easy)

Postby Symbol on Sun Jun 28, 2009 7:43 am

This should be rated as Extremely easy. Their are 3 different ways you can fix this.

1: You can add a space at the end of
Code: Select all
cout << "I love Marss++";


Entire code
Code: Select all
#include "stdafx.h"
#include <iostream>
using namespace std;

int main()
{
   cout << "I love Marss++ ";
   cout << "and I love programming" << endl;

   return 0;
}







2: You can add a space in front of
Code: Select all
cout << "and I love programming" << endl;




Entire code
Code: Select all
#include "stdafx.h"
#include <iostream>
using namespace std;

int main()
{
   cout << "I love Marss++";
   cout << " and I love programming" << endl;

   return 0;
}






Or you can just add both lines together.
Code: Select all
cout << "I love Marss++ and I love programming" << endl;


Entire Code
Code: Select all
#include "stdafx.h"
#include <iostream>
using namespace std;

int main()
{
   cout << "I love Marss++ and I love programming" << endl;
   return 0;
}








But I am pretty sure we all knew this, lol.
Symbol
 
Posts: 8
Joined: Sun Jun 28, 2009 2:30 am


Return to Debug

Who is online

Users browsing this forum: No registered users and 0 guests