stonecoldstevea 0 Newbie Poster

Just to clear up the air - When a string is inputed like below

Hello world! // The 3rd l, the space, the char r and the exclamation mark - must all be deleted and the string should the be like:

Helowold //then
Heowld //then
Hewl

stonecoldstevea 0 Newbie Poster

In this question you have to write a program consisting of two functions. A string has to be input in the main
function and then a string function, namely shorterString, has to be called to shorten the string by deleting
(“erasing”) every third character of the string. This has to be done repeatedly until the length of the string becomes
less than 6 and then the final string should be displayed by the main function. No global variables may be used.
Suppose, for example, the string
Hello world!
is input. Then
Helowold
should be returned to the main function by shorterString. Then, when the function is called again, the string
Heowld
should be returned. Then, when the function is called again, the string
Hewl
should be returned. This will be the final result (because its length is less than 6) and should be displayed.
Repeat the whole process described above for a number of strings until the string END is input. Use loops as
required. Run your program on the strings below and submit printouts of the program and output.
Cheers!
String manipulation is really not difficult.
Only two questions remain to be done.

Below is my code - but cannot get it to remove every 3rd character in a string - Help Please

using namespace std;
void shorterstring(string text)
{   
  for(int i =0; i <=0; i++)
  {text.erase(3,1);
  }
  cout<<text<<endl;
} …
stonecoldstevea 0 Newbie Poster

One-dimensional arrays in a function
Ten students do a multiple choice assignment consisting of twenty questions. The lecturer wants to display their
names and the mark obtained by each on the screen. Write a program to help him.
Declare two global constants, namely NR_STUDENTS (set equal to 10) and NR_QUESTIONS (set equal to 20). The
program should consist of three functions. No global variables may be used.
The main function:
Declare the following four one-dimensional arrays:
names of type string where the 10 names are to be stored,
correctAnswers of type intstoring the correct answers to the 20 questions,
answers of type int where the 20 answers of one student are to be stored,
marks of type int where the mark of each of the 10 students will be stored.

The array correctAnswers has to be initialised in the declaration statement.
The main function should contain a forloop going from 1 to 10. Inside the loop two functions have to be
called: the void function inputNameAndAnswers to input the name and answers of one student, and the
int function markOfStudentto calculate the mark of one student.
After the loop is exited, the names of all the students and the mark of each should be displayed on the screen.
The voidfunction inputNameAndAnswers:
The name and 20 answers of one student should be input in this function and made available to the main
function. …

stonecoldstevea 0 Newbie Poster

I need to validate the moduleCode by a do...while loop.
But my code does'nt exit the loop - Not sure if I did right thing by declaring the string ABC111 before the loop - please help urgently

using namespace std;
// function inputAndValidate should be inserted here
void inputAndValidate(string &moduleCode,int &numberHours)
{
string ABC111,DEF112,XYZ113;
do
{
cout << " Enter module code: ";
cin >> moduleCode;
}

while ((moduleCode!=ABC111) || (moduleCode!=DEF112) || (moduleCode!=XYZ113));
// while (moduleCode != ABC111);
// ||(moduleCode != DEF112) || (moduleCode != XYZ113));

cout << " Enter number of hours: ";
cin >> numberHours;

}
int main ()
{
string moduleCode;
int numberHours;

inputAndValidate(moduleCode, numberHours);

cout << " The module code is " << moduleCode;
cout << " and the number of hours is " << numberHours << endl;

return 0;
}

The while condition was messing me around - got it right finally -thanks to y'all

stonecoldstevea 0 Newbie Poster

your ABC111, DEF112, XYZ113 has no value...it will just continue to execute the do{} since the the while is giving off false boolean value...try giving it a value...
try this 1 and study the result...

void inputAndValidate(string &moduleCode,int &numberHours)
{
string ABC111 = "x";
do
{
cout << " Enter module code: ";
cin >> moduleCode;
}
 
while (moduleCode!=ABC111);
cout << " Enter number of hours: ";
cin >> numberHours;
 
}

enter "x" or any other value then study the result..

Have assigned a value to the string but when I assign values to the whole lo (DEF112 and XYZ113) it does'nt go out of the loop.
With the above mentioned method where ABC111 is given a value x,
then my output display x instead of ABC111 - on the cout statement

stonecoldstevea 0 Newbie Poster

I need to validate the moduleCode by a do...while loop.
But my code does'nt exit the loop - Not sure if I did right thing by declaring the string ABC111 before the loop - please help urgently

using namespace std;
// function inputAndValidate should be inserted here
void inputAndValidate(string &moduleCode,int &numberHours)
{
string ABC111,DEF112,XYZ113;
do
{
cout << " Enter module code: ";
cin >> moduleCode;
}

while ((moduleCode!=ABC111) || (moduleCode!=DEF112) || (moduleCode!=XYZ113));
// while (moduleCode != ABC111);
// ||(moduleCode != DEF112) || (moduleCode != XYZ113));

cout << " Enter number of hours: ";
cin >> numberHours;

}
int main ()
{
string moduleCode;
int numberHours;

inputAndValidate(moduleCode, numberHours);

cout << " The module code is " << moduleCode;
cout << " and the number of hours is " << numberHours << endl;

return 0;
}

stonecoldstevea 0 Newbie Poster

Need to write c++ code that calls a function and validate the moduleCode with a do...while loop.

I ca'nt get the function to go out the loop
Pleez help

void inputAndValidate(string &moduleCode,int &numberHours)
{
string ABC111,DEF112,XYZ113;
do
{
cout << " Enter module code: ";
cin >> moduleCode;
}

while ((moduleCode!=ABC111) || (moduleCode!=DEF112) || (moduleCode!=XYZ113));
cout << " Enter number of hours: ";
cin >> numberHours;

}
int main ()
{
string moduleCode;
int numberHours;

inputAndValidate(moduleCode, numberHours);

cout << " The module code is " << moduleCode;
cout << " and the number of hours is " << numberHours << endl;

return 0;
}

stonecoldstevea 0 Newbie Poster

Need help urgenlty -please
I'm new to the forum and request help

I need to write code containing a for loop from 1 to 30.everytime the loop is executed, the answers of one respondent to each of the 3 questins, should be inputed - Q1. how old are you, Q2, what is your gender. Q3 which of the following types of tv programs do you watch most often(choose one of N: News, S:Sport; M:Movies; E: Educational documentaries, O:Other and X: I do not watch Tv.
Validate the asnwer to Q2 using a do..while statement - you should threfore keep asking the person what his or her gender is until M or F is input.

The code has to compute four totals:
How many women older than 30 years do not watch TV at all
How mant women indicate M for their favourite
how many people younger than 20 years indicate S for their favourite
and how many men older than 35 years indicate S for their favourite.

They say - I need to initialise 4 totals
for loop over 30 people
input answer to Q1
input answer to Q2 and validate it usina do..while statement
input answer to Q3
a block of nested ifs where the correct total is incremented
display the four totals

I have started the code but got stuck with the do..while statement -
see code beloe:

#include <iostream>
using namespace std;
int …