Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

just wondering few things about c++


  • Please log in to reply
3 replies to this topic

#1 i am not known

i am not known

  • Members
  • 113 posts
  • OFFLINE
  •  
  • Local time:07:13 AM

Posted 04 December 2008 - 06:37 PM

hi i need help with a few things please explain these things for me please

how do you stop a programme from closing and instead start again

how would you go about making an if begin because the mouse was clicked

when i use the switch command why is it that what makes the case activate can only be one letter this is what i mean
#include "stdafx.h"
#include<iostream>
using namespace std;


int main(void)
{
	
	char cwhat;
	
	cin >> cwhat;

	
	switch (cwhat)
	{
	
	case 'o':


std::cout << "Enter the starting number part 1 > ";

	
  break;


	case 'b':
std::cout << "Enter the starting number part 2 > "; // this code means nothing just an example

   break;

	}
	system ("pause");
	return 0;
}
why is it i can't set it to use abc instead of o



and thanks to all who help my other post i was really new and had no idea what i was doing now simpaly need to get a few things right before i move on to more harder coding
I hear a boy only has a certain amount of tears one day the pain and dissapointment happen so often the pain dissapers and the boy becomes a man

BC AdBot (Login to Remove)

 


#2 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:05:13 AM

Posted 04 December 2008 - 06:56 PM

CHAR is a single character. You would need to allocate a null terminated string or a std::string class in order to use strings.

If you want a repeating program you can use a for loop for an infinite loop of the program like this:

int main() {
for (;;) {
if(userentered == 'q') {
break;
}
}
return 0;
}

A good tutorial on dealing with strings can be found here:
http://www.cplusplus.com/doc/tutorial/ntcs.html

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#3 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:06:13 AM

Posted 04 December 2008 - 07:12 PM

I edited your post to add the code tags so that your code was more readable.

how do you stop a programme from closing and instead start again

Billy already gave you an answer, except for one small problem. An infinite loop is a bad thing. You never purposely want to set up a condition where there can be an infinit loop. I don't think Billy really meant it that way though. I think what he really meant is that you want to create a control structure that loops until you tell it to stop.

There are other ways to explain what Billy is doing, but I want to make sure that you understand what control structures are, and sort of how they work. The answer to your question is that you do something like
Do something
While some condition is true

Basically, while some condition exists, then continue until the condition no longer exists.

As for your other questions, I guess I don't understand them at the moment.

how would you go about making an if begin because the mouse was clicked

when i use the switch command why is it that what makes the case activate can only be one letter this is what i mean

As a programmer, you should be very concerned with proper syntax and formatting. This translates into using proper grammar and punctuation when asking questions so that we know what you are talking about.

BTW, your formatting of your code is poor. Personally, if I find that someone does not take the time to properly format their code, or can not take the time to use proper grammar, I really don't have time to help. Understand?

#4 i am not known

i am not known
  • Topic Starter

  • Members
  • 113 posts
  • OFFLINE
  •  
  • Local time:07:13 AM

Posted 04 December 2008 - 09:28 PM

Well could you please explain how I should set out my codes i am very new at this. As for the grammar sorry I am not really good with english and was i guess I was excited because i was learning something I find fun but is completely new to me. So I am sorry I can't spell or write properly but I really do want to get better at programming and even though I am going to be a slow learner, forgive me i am trying.

Thankyou for all your help.

Oh and I tryed a for loop and yes I think I get how it works now but I don't think its what I need. It may be just what I need for my very old project button press counter. How would I make it so even when I am not looking at the programme it will still keep going.

Edited by i am not known, 05 December 2008 - 04:52 PM.

I hear a boy only has a certain amount of tears one day the pain and dissapointment happen so often the pain dissapers and the boy becomes a man




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users