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>!

New at this, why dont this work?

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

New at this, why dont this work?

Postby exa1292 on Wed Aug 05, 2009 9:26 am

Code: Select all
#include "stdafx.h"


#include <iostream>
double dfirstnumber;
double dsecondnumber;
using namespace std;

int main()
{
   cout << "Are u 18? " << endl;
   int dfirstnumber = 18;
   cin >> dsecondnumber = 18;
      if (dsecondnumber < 18)
         cout << "Access Granted \n";
      else (dsecondnumber > 18);
         cout << "lol nothing for you " << endl;
         


   


   cin.get();
   return 0;
}
exa1292
 
Posts: 1
Joined: Wed Aug 05, 2009 9:19 am

Re: New at this, why dont this work?

Postby DevGeek++ on Wed Aug 05, 2009 9:42 am

Take a look at this code :

#include <iostream>
int dfirstnumber;

using namespace std;

int main()
{
cout << "Are u 18? " << endl;
cin >> dfirstnumber;
if (dfirstnumber <= 18)
cout << "Access Granted \n";
else
{
cout << "lol nothing for you " << endl;

}




cin.get();
return 0;
}
DevGeek++
 
Posts: 28
Joined: Tue Aug 04, 2009 5:54 am

Re: New at this, why dont this work?

Postby learning in progress on Wed Aug 05, 2009 9:49 am

umm first reason
i decalred it as double and tried to use it as int
second reason is u cannot use cin >> if ur gonna give it the value yourself
and after u have used cin >> i beleive u cant use cin.get
try this

Code: Select all

#include "stdafx.h"


#include <iostream>

using namespace std;

int main()
{
   int dsecondnumber;
   cout << "Are u 18? " << endl;
   cin >> dsecondnumber ;
      if (dsecondnumber < 18)
         cout << "Access Granted \n";
      else
         cout << "lol nothing for you " << endl;
         
   char f;
   cin>>f;
   return 0;
}



also just a suggestion:do not create Global variable unless u really need it :D
learning in progress
 
Posts: 11
Joined: Thu Jul 09, 2009 4:15 pm


Return to Debug

Who is online

Users browsing this forum: No registered users and 0 guests