C++ ::  How To Make A Loop Until User Asks To Break

Apr 4, 2013

I'm making a program for a MMO I play. It calculates the cash and resources needed to build certain 'modules'. I'm having trouble to do something very simple : make a loop until the user asks to break the loop. Here is what the interface looks like :

What module do you want to install?

(Examples: 'Avenger' or 'VLLT')

dd // I input this
DD. COST each : 60,000 cr.

How many do you want? (Modules left:15)
(NOTE : You may enter a negative number if you made a mistake)
3 // I input this
Current Total Module Price : 180000 cr
+6 droids

[Code] ....

The bigger code box below is a part of the code I made. What I deleted is uninteresting, it's just the same thing again : other resources, other 'modules'...

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
struct resources// Defines the amount of resources and their price

[Code] ....

View 8 Replies


ADVERTISEMENT

C :: Make Program That Asks User For Number?

Oct 15, 2013

So I'm trying to make a program that asks the user for a number and then prints a statement the same number of times the user entered. 3 different statements, using the 3 loops (for, while, and do while). I made the program but for some reason the statement from the do while loop goes off infinitely.

MY CODE:

The error:

View 8 Replies View Related

C/C++ :: How To Use Alphabets To Break Do While Loop

Jul 29, 2014

#include<iostream>
using namespace std;
int main() {
int choice[10] = { 0 };
int vote, highvote;
cout << "1 Lional Messi ";

[code]....

My problem is i have to stop the loop when i enter any alphabets, i tried a lot of method but still doesn't work.

View 5 Replies View Related

C++ :: Using Break In Void Function That Does Not Contain A Loop

Jan 14, 2015

I need this break in my main function, but I'm not allowed to put it in void since void is not located in a loop. How can I solve this?

Code:
#include <iostream>#include <string>
using namespace std;
void login(string x, string y);
string username;
string password;
string x;
string y;

[Code] ....

View 6 Replies View Related

C/C++ :: Break Out Of Loop When A Certain Word Or Phrase Is Entered

Dec 24, 2014

The code below replaces lowercase characters by upper case and uppercase character by lowercase. Also, I should be able to break out of the loop when I enter 'exit'. It does what it is supposed to do. But I had to come up with a function to break out of 'the while loop'. Is there any shorter or more concise way to break out of the loop when 'exit' is entered?

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

[Code]......

View 5 Replies View Related

C++ :: Write A Program That Asks The User For A Name

Jul 2, 2014

So I am trying to write a program that asks the user for a name. If the user enter the right name the program ends but if the user were to enter the wrong name the program would enter a loop prompting the user to re-enter the name. However I am not able to get the program to work!

View 9 Replies View Related

C++ :: Program That Asks User To Enter Even Number Only

Mar 23, 2014

Write a C++ program that asks the user to enter an even number only. If the user enters an odd number the program should use input validation to ask the user to enter another number.

- The user can enter as many numbers as he wants

- The program should also keep a count of how many numbers entered and display how many odd and even numbers entered.

View 1 Replies View Related

C/C++ :: Write A Program Where It Asks The User For A File Name?

Apr 18, 2014

I'm trying to write a program where it asks the user for a file name.

If that file exists, the it will open the file and then read it and print the information in the file.

However, if the user enters a file name that does not exist, the user will have 2 more tries (for a total of 3 tries) to get the correct name of the file.

I am close to getting it. What I have now just won't go through the loop to validate if the input matches an existing file. It goes straight to the printing of what is in the file. If the file doesn't exist, it prints: "Found your file..Opening..processing...Total keys found = 0."

So, my question, what am I doing wrong that it won't go through the loop properly?

#include<iostream>
#include<iomanip>
#include<fstream>
#include<string>
using namespace std;
int main() {
bool fileFound = false;

[code]....

View 2 Replies View Related

C :: Program That Asks The User To Type 10 Integers Of Array?

Mar 2, 2014

Write a program that asks the user to type 10 integers of an array. The program will then display either "the array is growing", "the array is decreasing", "the array is constant", or "the array is growing and decreasing."

(Hint: compare consecutive numbers in array and check whether it is increasing or not or constant) I wrote the program very well, but do I have to use "bool" like in c++ ? I haven't known how to code in c++ yet.So, I don't want to use "bool" in C.

I also wrote code about it but it looks like backslash and one,two,three,four,five how can I do it like this ?

View 4 Replies View Related

C++ :: Program That Asks User To Prompt Integer Number

Nov 18, 2013

Write a program that asks the user to prompt an Integer number and then test whether it is Palindrome Numbers or not.

The following are Palindrome numbers:
1.22
2.333
3.67876
4.44444
5.123454321

View 8 Replies View Related

C++ :: Writing Program That Asks User To Input Number?

Sep 11, 2013

im writing a program that asks the user to input a number 1-10 and will transform it into the roman numeral of that number but it seems that its not after the user inouts the number nothing will output

#include <iostream>
#include<iomanip>
using namespace std;

[Code]....

View 3 Replies View Related

C++ :: Program That Asks User For Numbers And Adds Odd Ones Doesn't Work

Nov 12, 2014

Title is self-explanatory.

Code:
#include <iostream>
using namespace std;
int main ( ) {
float number;
float sum;
float divi;
while(number != -1) {

[Code] .....

View 5 Replies View Related

C++ :: Write Program That Asks User To Enter Student Grades?

Jan 21, 2014

Write a program that asks the user to enter a student’s grades on four exams. The program should display the four grades and the average of the four grades,rounded to the nearest tenth. To add the grades, use a variable called total_grade, which you should initialize to zero.As the program prompts for and obtains each grade, add the grade to total_grade using the += operator.

View 3 Replies View Related

C :: Create A Program That Asks User To Input Integer Lengths Of Three Sides Of A Triangle

Sep 6, 2013

C programming: I want to creat a program that asks the user to input the integer lengths of three sides of a triangle, and if so whether the triangle is a right-angled, acute or obtuse one. i am having some doubts about the if, else if statements. I never seem to know how and in what order to use them.

Code:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(int argc, char *argv[]){
int SideA;
int SideB;
int SideC;
}

[code]....

View 14 Replies View Related

C :: Asks To Input Number Nad If Outside Number Asks To Put In Number Within Bounds

Mar 23, 2013

I have to write a program that will ask you to put in a number between 0 and 9 and multiply it by pi. If the number put in is between 0 and 9 then pi is multiplied but if it isnt between 0 or 9, it will say the number is not between 0 and 9 and asks you to put it in again and will repeat until a number between 0 and 9 is put in.

I have got the program working to the extent that it the number is between 0 and 9 it will multiply it by pi but if its not between 0 and 9 it will say the number is not between 0 and 9 and ask to put in a new number.

I can't work out how to get the program to repeat itself if the number entered isnt between 0 and 9.

I have enclosed the code below .....

View 5 Replies View Related

C :: Make A Program Using While Or For Loop?

Nov 20, 2014

I'm trying to write a program for a lab, I know how easy it is but cant see to crack it.

I need to make a program using while or for loop.

I must have the user type a number, for an input value an output value but then do it again several times but without it going on forever asking again and again.

View 4 Replies View Related

C++ :: How To Make A Loop So Program Never End

Aug 29, 2014

How to make a loop so program never end, it end only by typing "EXIT"

View 1 Replies View Related

C/C++ :: OpenMP Can Make For Loop Faster?

Dec 9, 2014

I'm trying to optimize this code using openMP. The line I added made it run about twice as fast but I'm trying to figure out how to make it even faster. Could reshaping the loops potentially increase the speed?

//4 threads
int listsize=15000;
#pragma omp parallel for shared(f) private(i,j,hash)
for(i = 0; i < listsize; i++) {
printf("Thread: %d i: %zu wl_size: %zu
",omp_get_thread_num(),i,wl_size);
for (j = 0; j < num; j++) {
h = f[j] (getw(list, i));
c[h] = 1;
} }

View 2 Replies View Related

C++ :: Make A Loop Inside A Condition?

Oct 26, 2013

I need to do make a loop inside a condition. Can it be done? I don't want to call another function to do it. Any way at all without calling separate function inside the if? I just want to do:

if (
for (int i = 0; i<=10; i++)
{
//stuff related to the for loop
} )
{
//stuff related to the initial if condition
};

View 7 Replies View Related

C :: Make A Program That Multiplies Loop Variable By 2

Nov 15, 2013

I have an exam in C programming I'm a little stuck on loops..I have to make a program that multiplies the loop variable by 2 then takes away 1... easy, that was a for loop no problem

for (x=3; x<=65; x=x*2-1)

that should print out 3 5 9 17 33 65 however, my lecturer has given the task for it to reverse, but not to display the number 17 on the way back down using an if statement...however, this time it must be a do while loop... This is what I have so far.

Code:

#include <stdio.h>
#include <stdlib.h>
int main()
{
int x = 129;
}

[code]....

View 7 Replies View Related

C++ :: How To Make Loop That Reiterates For Certain Number Of Players

Dec 11, 2013

Something that does something like this

at this point run a loop for all players, in this loop use random to determine the face and depending on the face run a loop (for roll again etc) or give next user the chance.

And this loop is 2-12 people, all rolling die.
They draw 3 die out of a cup of 12.
Then they roll the 3 die, getting fish, hook, or boot on each die.

View 1 Replies View Related

C++ :: How To Make A Loop That Keeps Track Of Whose Turn It Is And Their Score

Dec 11, 2013

[URL] ....

This is my code, but how can I implement this?

View 1 Replies View Related

C :: How To Make A Switch Case Loop After Input Entered

Dec 31, 2013

I'm working on a code that needs to loop a switch case back to the beginning after a certain input is entered.

ex) Code:

printf("Select an option);
printf("1. Play game");
printf("2. Status");
printf("3. Exit");
scanf("%i", &userinput);
switch(userinput);

[Code]...

For my program, I want option 2 to display something, then loop back to "select and option" after the user presses enter. How would I write that? Would i use a while? do while?

View 3 Replies View Related

C++ :: Program To Make A Table For Any Input Number - Do While Loop

Nov 27, 2014

Write a program to make a table for any input number and then continuesly ask to press y to print more table and if you press any key other than y then program must be terminate using while loop and do while loop. How to start or end with it.

View 2 Replies View Related

C++ :: While Loop - Use Non-recursive Function To Make Triangle Number Sum Of All Whole Numbers From 1 To N

Jul 31, 2014

My while loop is the problem. I want to use a non-recursive function to make the triangle number the sum of all whole numbers from 1 to N.

#include "stdafx.h"
#include <iostream>
using namespace std;
int triangle(int t);

[Code] ....

View 2 Replies View Related

C/C++ :: Shifting Characters - How To Make Letters Loop Back To The Start

Feb 9, 2015

I have to make a function that i'll later be able to use for a ceasar cypher. The letters should shift a user inputted number. This is what I have so far:

char shiftChar(char c, int s) {
char ch = c;
int shift = s;
int newC;
newC = int(ch) + shift;
return newC;
}

The problem with this, is that it doesn't loop back to the start of the alphabet once i get past z.

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved