So I noticed that both for and while loops have a infinite loop option, is there any difference between them?
- Viewing Profile: Topics: Kalner
Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics
Community Stats
- Group Members
- Active Posts 23
- Profile Views 521
- Member Title Member
- Age Age Unknown
- Birthday Birthday Unknown
-
Gender
Not Telling
120
Neutral
User Tools
Contacts
Kalner hasn't added any contacts yet.
Latest Visitors
Topics I've Started
for and while inifite loops
28 December 2012 - 04:22 PM
Getting something to run code again.
16 March 2012 - 07:55 PM
Say I have a switch statement with certain parameters, but when someone doesn't input what it ask's, I want the default to go back to the switch statement instead of making another one.
Declaring Variables outiside int main
06 March 2012 - 04:13 PM
Just asking if it is possible to declare variables outside int main, any functions and outisde classes?
Wierd Code 0.o
20 February 2012 - 06:09 PM
So today I was getting into reading more on classes and I read on classes in seperate files and it was like Myclass::Myclass or something
so.. what does the "::" mean??
so.. what does the "::" mean??
Switch and If/else C++
19 February 2012 - 09:12 AM
So, yesterday I started making a geuss the number game and there was a problem that if you geussed it right it would show a loss.I tried today of using classes for losses instead of a bunch of code in the if and else curly brackets. Now even with class's I still get an error. Is there some kind of prblem with my if statement or is there a problem when an if statement is in a switch?
This is 1/3 of the whole program.
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
using namespace std;
class Win{
public:
void setWin(string x){
win = x;
}
string getWin(){
return win;
}
private:
string win;
};
class Loss{
public:
void setLoss(string z){
loss = z;
}
string getLoss(){
return loss;
}
private:
string loss;
};
int main()
{
int number;
char gn;
char dif;
srand(time(0));
Win wo;
wo.setWin("You Won!");
Loss lo;
lo.setLoss("You Lost, the number was ");
cout << "Welcome to Guess The Number 3.0" << endl;
cout << "Please choose your difficluty. E = Easy M= Medium H = Hard" << endl;
cin >> dif;
switch(dif){
case 'e':
case 'E':
number = 1+(rand()%10);
cout << "Guess a number beetween 1 and 10" << endl;
cin >> gn;
if(gn == number){
cout << wo.getWin() <<endl;
system("PAUSE");
}
else{
lo.getLoss() << number << endl;
system("PAUSE");This is 1/3 of the whole program.
- Home
- » Viewing Profile: Topics: Kalner

Find content