Still learning C++, thought I knew more than I did and was quite wrong, so reaching out for a little help. Below are three sources for a few basic programs I'm writing, a little help with each would be great! The funciton/error of the programs are below.
Program 1:
//Counter program, count to, count from - count to work fine
//but the count by function doesn't, as in if it's above 1
//it doesn't work, like count 1 - 10 by two should be
// 2 4 6 8 10, but it outputs something else and
//not sure how to fix this
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
int c1, c2, c3, c4;
cout << "Please enter where you would like to count to: ";
cin >> c1;
for (int count = 1; count <= c1; count++){
cout << count << " ";
}
cout << endl;
cout << "Please enter where you would like to count from: ";
cin >> c2;
cout << "Please enter where you would like to count to: ";
cin >> c3;
cout << "Please enter what you would like to count by: ";
cin >> c4;
for (int count2 = c2; count2 <= c3; count2++){
//int count3 = count2 * c4;
cout << count2 << " ";
}
cout << endl;
system("PAUSE");
return 0;
}
Program 2
//for some reason the math isn't right in this, and the loop makes the
//sum wrong
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
int n_grades = 0, grade = 0;
double sum_grades = 0, average_grades = 0;
cout << setprecision(2) << setiosflags(ios::fixed) << setiosflags(ios::showpoint);
cout << "How many grades are you going to enter?: \n";
cin >> n_grades;
for (int count = 1; count <= n_grades; count++){
cout << "Please enter grade: \n";
cin >> grade;
sum_grades = grade + grade;
}
average_grades = sum_grades / n_grades;
cout << "The total number of grades are: " << n_grades << endl;
cout << "The sum of all grades are: " << sum_grades << endl;
cout << "The average of all the grades are: " << average_grades << endl;
system("PAUSE");
return 0;
}
Program 3
//Need to figure out compound/simple interest, no ######ing idea what I'm doing lol
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main(){
double prin, rate, time, simpleInterest, simpleBalance, compoundInterest, compoundBalance, final_rate;
cout << setprecision(2) << setiosflags(ios::fixed) << setiosflags(ios::showpoint);
cout << "Enter principle: \n";
cin >> prin;
cout << "Enter rate(%): \n";
cin >> rate;
cout << "Enter Time(years): \n";
cin >> time;
final_rate = rate / 100;
simpleInterest = prin*final_rate*time;
compoundInterest = prin*pow(1 + rate / 100, time);
simpleBalance = prin + simpleInterest;
compoundBalance = prin + compoundInterest;
//output - simple interest
cout << "Simple Interest \n";
cout << "Interest came to: " << simpleInterest << endl;
cout << "Balance is: " << simpleBalance << endl;
//output - compound interest
cout << "Compound Interest \n";
cout << "Interest came to: " << compoundInterest << endl;
cout << "Balance came to: " << compoundBalance << endl;
system("PAUSE");
return 0;
}
Question
coolbunny1234
Still learning C++, thought I knew more than I did and was quite wrong, so reaching out for a little help. Below are three sources for a few basic programs I'm writing, a little help with each would be great! The funciton/error of the programs are below.
Program 1:
Program 2
Program 3
Thank you!
Link to comment
Share on other sites
10 answers to this question
Recommended Posts