N00b N00b N00b help the N00b

Started by
6 comments, last by Bagel Man 19 years, 6 months ago
ok,ok, here is what i have been working on.....
#include <iostream>
#include <ostream>
#include <istream>
#include <stdlib.H>

using std::cin;
using std::cout;

int main ()
{
int x=5;
int i;

cout << "enter the number five";
cin >> i;
if (i==x)
cout << "well done!";
else
cout << "i said type five dumbass";
system("PAUSE");
return(0);
}


first thing,i have done an if statement. After the else i want to do another if statement but i don't want this if statement to happen under the else section. How do i seperate it so it is not part of the else line? second thing, i have added 'system("pause") and i want it to be on a new line than my cout << ""; when i put '\n' it doesn't work, why not?
Advertisement
First, name your post something relevant. All the 'noob's are getting annoying to read.

Anyway, as for if, else's I'm not totally clear on what you're asking. Regardless:
int x = 1;if (x==1){   // the code goes here}else {   // the code does not go here}if(x==5) {    // this is seperate from the above if/else match}
If a plant cannot live according to its nature, it dies; so a man.
try this
#include <iostream>
#include <ostream>
#include <istream>
#include <stdlib.H>

using std::cin;
using std::cout;

int main ()
{
int x=5;
int i;

cout << "enter the number five";
cin >> i;
if (i==x)
{
cout << "well done!";
else
cout << "i said type five dumbass";
};
if(//case)
{
//whatever you want to go here
};
system("PAUSE");
return(0);
}

____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
when you don't put { and } after if or else only the next line is part of the if or else statement like this:
if(i == 2)  cout << "this is printed only if i == 2" << endl;else  cout << this is printed only if i != 2" << endl;// whatever you put after this will be executed outisde of the if/else statementcout << "This line is always printed" << endl;


if you want to execute more than one line in an if/else statement you do like this:
if(i == 2){  cout << "this is printed";  cout << "only if i == 2" << endl;}else  cout << "this is printed only if i != 2" << endl;cout << "this is always printed" << endl;


this is also true for do/while, for, and any other control statement

hope that helps !
Matt
Matt
This code here is modified for you:

#include <iostream>#include <ostream>#include <istream>#include <stdlib.H>using std::cin;using std::cout;int main (){   int x=5;   int i;   cout << "enter the number five";   cin >> i;   if (i==x)      cout << "well done!" << endl; //*CHANGED*      system("PAUSE"); //*CHANGED*   else   {      cout << "i said type five dumbass" << endl; //*CHANGED*      system("PAUSE");   }   return(0);}


Quote:first thing,i have done an if statement. After the else i want to do another if statement but i don't want this if statement to happen under the else section. How do i seperate it so it is not part of the else line?


Here is an example of what you are trying to achieve with explainations:
/***************if statement #1***********************/int a = 1;int b = 0;if (a=1)    b = a; /* Here you dont need any opening and closing braces              because the if statement only processess one line              of code *//***************if statement #2***********************/int a = 1;int b = 0;if (a=1){    a = a + 1;       b = a } /* Here you do need opening and closing braces because the     if statement processes more than one line of code *//***************if/else statement***********************/int a = 1;int b = 0;if (a=1){    a = a + 1;       b = a } else    cout << "a != 1"; /* Notice i didnt use any opening and                          closing braces for this else statement.                         I'll leave it to you to figure why ;) */


Quote:second thing, i have added 'system("pause") and i want it to be on a new line than my cout << ""; when i put '\n' it doesn't work, why not?


Just use the 'endl' in the first code I posted above... not really much to explain. 'endl' = "endline"
HHC 1st Battalion, 5th Infantry Regiment1st Brigade (SBCT), 25th Infantry DivisionRest In Peace SSG Julian Melo
Hmm, that game wasn't very hard at all. I managed to beat it in only 30 hours!

*** SPOILERS AHEAD ***

Beat the final boss by pressing "5";
Erm, out of curiosity, why does x exist? just put if (i == 5)

-Dan
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."
Good lord, someone asks a question on one of the most basic parts of the C syntax and gets two responses that are not only wrong, but wouldn't even compile??

This topic is closed to new replies.

Advertisement